일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- #alert#자바스크립트#radio#check
- #select#from#distinct
- #C언어#if
- #db#order#by
- #C언어#do#while#계산기
- #db#where
- #자바스크립트#alert
- #html#테이블#table
- #자바스크립트#시계#실시간시계
- #C언어#switch#case#계산기#함수
- #C언어#사각형
- #자바스크립트#접속시간#시간
- #C언어#do#while#계산기#함수
- #db#데이터베이스#select
- #자바스크립트#만년달력#달력
- #클릭#숨기기#보이기
- #db#froup#by
- #db#join#inner#cross
- #C언어#성적처리#점수#등급
- #C언어#숫자비교#삼항연산자
- #jQuery#mouse#over
- #증감#연산자
- #C언어#scanf#fflush
- #getElementById#id
- #alert#자바스크립트#checkbox#alert
- #html#프레임
- #자바스크립트#회원가입#유효성#검사
- #자바스크립트#텍스트#알람#alert
- #C언어#for#간단#예제
- #C언어#타입#printf
- Today
- Total
선택장애
JSP - Application(name이름넘기기, count값 올리기) 본문
application.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<h1>application 예제</h1>
<hr>
1. 서버 정보 : <%= application.getServerInfo() %> <br>
2. 서블릿 API 버젼정보 : <%= application.getMajorVersion() + "." +application.getMinorVersion() %> <br>
3. application.jsp 화일의 실제 경로 : <%= application.getRealPath("application.jsp") %> <br>
<hr>
setAttribute 로 username 변수에 "홍길동" 설정 <p>
<% application.setAttribute("username","홍길동");
application.log("username=홍길동");
application.setAttribute("count", 1);
%>
<a href = "application3.jsp">확인하기</a>
</body>
</html>
application3.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
USERNAME 에 설정된 값은 :<br>
<%=application.getAttribute("username")%><br>
<%
//application scope에 저장된 count 라는 이름의 Integer 객체를 가져옴.
Integer count = (Integer)application.getAttribute("count");
//랩퍼 클래스인 Inter를 int형으로 만들어 1을 더함.
int cnt = count.intValue()+1;
application.setAttribute("count", cnt);
%>
<%//새로 고침하면 1씩 카운터가 올라간다. %>
count : <%= cnt %>
</body>
</html>
아니면 똑같은 결과 또 다른 방법
application3.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
USERNAME 에 설정된 값은 :<br>
<%=application.getAttribute("username")%><br>
<%
//application scope에 저장된 count 라는 이름의 Integer 객체를 가져옴.
String I = application.getAttribute("count").toString();
//랩퍼 클래스인 Inter를 int형으로 만들어 1을 더함.
int num=Integer.parseInt(I)+1;
application.setAttribute("count", num);
%>
<%=application.getAttribute("count") %>
</body>
</html>
'JSP' 카테고리의 다른 글
JSP - 장바구니(물건추가, 로그아웃)Session (0) | 2017.08.14 |
---|---|
JSP - Sesstion(alert) (0) | 2017.08.14 |
JSP - request사용하기 (select와 checkbox값받기) (0) | 2017.08.14 |
JSP - Forward_Action, response.sendRedirect (0) | 2017.08.14 |