-
jsp:액션태그,우편번호APIJAVA 2021. 8. 10. 23:23
JSP 액션태그
1. <jsp:include page = "외부파일명" flush="false" />
처리 흐름이 외부 파일로 이동하였다가 다시 온다. ( 현재페이지에 설정페이지가 화면에 나온다. )
데이터 전달: request 객체, param 액션 태그로 화면 레이아웃의 일 부분 모듈화시 용이.2. <jsp:forward page="파일명" />
설정 페이지로 프로그램 제어가 이동 ( 주소창은 현재 페이지이지만 설정 페이지가 화면에 나온다. )
request 의 forward(request,response) 와 같다.3. <jsp:param name="매개변수명" value="값" />
include, forward 액션 태그 안에서 사용.
request.setParameter("매개변수명") 과 같다.
include, forward 의 설정페이지에서 getParameter() 해서 value 를 얻어내거나 jstl 인 ${} 로 바로 가져올 수 있다.
단 ${} 는 setAttribute() 로 넘어온 경우는 ${key이름}
<jsp:param> 으로 넘어온 경우는 ${param.key이름} 으로 사용해야 한다.어디까지나 자바코드를 모르는 디자이너들이 사용하기 좋은 코드들이다.
jsp:include 는 사용해도 좋을듯하나 jsp:forward 는 업무코드, 즉 조건에 따라 forward 할 수 없는 구조적이지 않은 코드다.
1. include 액션태그 (+ param 액션태그)
>> 상단.jsp
<body> <h1>상단내용</h1> </body>
>> 내용A.jsp
<% request.setCharacterEncoding("utf-8"); String 제목 = request.getParameter("제목"); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <h2>내용A</h2> <%if(!(제목==null)){%> <%=제목 %> <% }%> </body> </html>
>> 내용B.jsp
<body> <h2>내용B</h2> </body>
>> 프레임.jsp
<body> <div class="상단"> <jsp:include page="상단.jsp"/> </div> <div class="내용"> <jsp:include page="내용A.jsp"/> </div> <div class="내용"> <jsp:include page="내용B.jsp"/> </div> </body>
>> 프레임2.jsp
<% request.setCharacterEncoding("utf-8"); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <div class="상단"> <jsp:include page="상단.jsp"/> </div> <div class="내용"> <jsp:include page="내용A.jsp"> <jsp:param name="제목" value="제목1"/> </jsp:include> </div> </body> </html>
2. forward 액션태그
>> 부터.jsp
<% request.setAttribute("key2", "value2"); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> 부터의 내용 <jsp:forward page="로.jsp"> <jsp:param name="key1" value="value1"/> </jsp:forward> <!-- 위 아래가 같은 내용이다. --> <% RequestDispatcher rd = request.getRequestDispatcher("로.jsp"); rd.forward(request, response); %> </body>
>> 로.jsp
<% String value1 = request.getParameter("key1"); String value2 = (String)request.getAttribute("key2"); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> 로의 내용 <br /> <%=value1 %> <br /> ${param.key1} <br /> ${key2} </body> </html>
'JAVA' 카테고리의 다른 글
[java] 디자인패턴 - Adapter (0) 2021.08.11 [mybatis] Persistence Framework (0) 2021.08.11 [spring] tiles: 동적배치 (0) 2021.08.10 [spring]board Business,Dataservice(xml방식) (0) 2021.08.06 [spring]member Presentation (0) 2021.08.05