JAVA/JSP

페이지 상태 유지

CitronLemon 2019. 3. 5. 11:30

페이지 상태 유지                페이지가 연속적으로 이동할 때 이전 페이지의 변수를 유지해야 할 경우 사용할 수 있는 기법.



GET 방식의 경우


이전 페이지에서 전달된 파라미터를 URL에 누적시켜 전달한다.


1
2
3
4
5
<% 
    String w = request.getParameter("w");
    String h = request.getParameter("h");
%>
<a href = "hello.jsp?w=<%=w%>%h=<%=h%>&name=helloworld>click</a>
cs





POST방식의 경우


이전 페이지에서 전달된 파라미터를 hidden field에 포함시켜 submit 처리한다.


1
2
3
4
5
6
7
8
<% 
    String w = request.getParameter("w");
    String h = request.getParameter("h");
%>
<form method="post" action="foo.jsp">
    <input type="hidden" name="w" value="<%=w%>" />
    <input type="hidden" name="h" value="<%=h%>" />
</form>
cs





1
2
3
<ul>
    <li>...</li>
    <input type="hidden">
cs