WEB/JSP

[JSP] ch03-02. Request

밍글링글링 2017. 11. 13.
728x90

3-2. Request

requestParamin.html

<!DOCTYPE html>
<html lang="ko">
<head>
<title>requestParam</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
</head>
<body>
    <h2>설문 조사</h2>
    <form action="requestParamOut.jsp" method="post">
        <table>
            <tr>
                <th>이름</th>
                <td><input type="text" name="userName" size="10"/></td>
            </tr>
            <tr>
                <th>성별</th>
                <td>
                    <input type="radio" name="gender" value="male" checked>남
                    <input type="radio" name="gender" value="female">여
                </td>
            </tr>
            <tr>
                <th>좋은 계절
                <td>
                    <input type="checkbox" name="season" value="봄">봄
                    <input type="checkbox" name="season" value="여름">여름
                    <input type="checkbox" name="season" value="가을">가을
                    <input type="checkbox" name="season" value="겨울">겨울
                </td>
            </tr>
            <tr>
                <th>직업</th>
                <td>
                    <select name="job">
                        <option>회사원</option>
                        <option>자영업</option>
                        <option>학생</option>
                    </select>
                </td>
            </tr>
        </table>
        <input type="submit"/>
    </form>
</body>
</html>

 

requestParamOut.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% 
    request.setCharacterEncoding("utf-8");
    String userName = request.getParameter("userName");
    String gender = request.getParameter("gender");
    String[] seasons = request.getParameterValues("season");
    String job = request.getParameter("job");
%>
답변 확인
<table>
    <tr>
        <th>이름</th>
        <td><%=userName%></td>
    </tr>
    <tr>
        <th>성별</th>
        <td>
            <%
                if(gender.equals("male")) gender="남";
                else gender="여";
           %><%=gender%>
        </td>
    </tr>
    <tr>
        <th>좋은 계절</th>
        <td>
            <%
             for(String season:seasons) out.print(season+" ");
           %>
        </td>
        <th>직업</th>
        <td><%=job%></td>
    </tr>
</table>
 
 
requestMethod.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<ul>
    <li>getContextPath(): <%=request.getContextPath()%></li>
    <li>getMethod(): <%=request.getMethod()%></li>
    <li>getRequestURL(): <%=request.getRequestURL()%></li>
    <li>getRequestURI(): <%=request.getRequestURI()%></li>
    <li>getQueryString(): <%=request.getQueryString()%></li>
    <li>getServerName(): <%=request.getServerName()%></li>
    <li>getProtocol(): <%=request.getProtocol()%></li>
</ul>

 

 

728x90

'WEB > JSP' 카테고리의 다른 글

[JSP] ch03-05. Forward Login  (0) 2017.11.13
[JSP] ch03-04. Redirect Login  (0) 2017.11.13
[JSP] ch03-01. FOR문  (0) 2017.11.13
[JSP] ch02-08. Include2  (0) 2017.11.13
[JSP] ch02-07. Include  (0) 2017.11.13

댓글