Notice
Recent Posts
Recent Comments
Link
«   2025/06   »
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
Archives
Today
Total
관리 메뉴

개발기록

10 JSP request, response 본문

JSP

10 JSP request, response

옥수수수염챠 2020. 3. 19. 15:27

사용자의 요청(Request)과 web-server의 응답(Response)를 담당하는 객체에 대해서 학습한다.

 

10-1 request 객체

아래 HTML 파일을 통해 웹사이트로의 방문이 가능하고, 폼 데이터를 통해 submit시 데이터가 서버로 전송된다.

 

클라이언트단 html 파일 

<!-- formEx.html-->
<!DOCTYPE html>
<html>
<body>
	<form action="mSignUp.jsp" method="get">
    	name : <input type="text" name="m_name"><br>
        password : <input type="password" name="m_pass"><br>
        hobby : sport<input type="checkbox" name="m_hobby" value="sport">,
        		cooking<input type="checkbox" name="m_hobby" value="cooking">,
                travel<input type="checkbox" name="m_hobby" value="travel"<br>
        <input type="submit" value="sign up">
    </form>
</body>
</html>

 

서버단 JSP파일 

<!-- mSignUp.jsp-->
<!DOCTYPE html>
<html>
<body>
	<%!
    	String m_name;
        String m_pass;
        String[] m_hobby;
    %>
    <%
    	m_name = request.GetParameter("m_name");
        m_pass = request.GetParameter("m_pass");
        m_hobby = request.GetParameterValues("m_hobby");
    %>
    m_name : <%= m_name %> <br>
    m_pass : <%= m_pass %> <br>
    m_hobby : <%
    			for(int i=0; i < m_hobby.length; i++){
               	%>
                	<%=m_hobby[i]%>
                <%
                }
                %><br>
     
</body>
</html>

- servlet은 서버를 재구동 해야하지만, JSP는 서버를 재구동 하지 않아도 적용된다.

10-2 response 객체

클라이언트에게 응답을 해준다.

firstPage.jsp 

<!-- firstPage.jsp -->
<!-- 위 메타태그등 불필요한 요소들은 생략하였습니다-->

<html>
<body>
	<p>First Page</br>
    <%
    	response.sendRedirect("secondPage.jsp");
    %>
</body>
</html>

secondPage.jsp

<!-- secondPage.jsp -->
<!-- 위 메타태그등 불필요한 요소들은 생략하였습니다-->

<html>
<body>
	<p>Second Page</br>
    
</body>
</html>

 

위와 같이 작성시, firstPage를 접근한 클라이언트는 바로 secondPage로 방문하게 된다.

'JSP' 카테고리의 다른 글

13 Cookie  (0) 2020.03.19
12 Servlet 데이터 공유  (0) 2020.03.19
9 JSP 스크립트  (0) 2020.03.19
5 Servlet 맵핑  (0) 2020.03.15
웹 프로그램 개요  (0) 2020.03.11