IT/Jsp

jsp - form 입력값 전송, request 객체, request.getParameter("파라미터이름")

노마드오브 2018. 9. 3. 22:23

<%@ 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">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

<h1>testForm1.jsp 페이지</h1>

<hr>

<form action="testPro1.jsp" method="get">

<input type="text" name="num"><br>

<input type="submit" value="전송">

</form>

</body>

</html>



<%@ 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">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

<!-- http://localhost/jspstudy/jsp2/testPro1.jsp?num=5 -->

<!-- request 객체 : 요청정보를 저장하는 객체 -->

<!-- request 파라미터정보 가져오기  .getParameter("파라미터이름") -->

<%

String strNum = request.getParameter("num");

// String형 -> 정수형

int num = Integer.parseInt(strNum);

%>

파라미터값 문자열 : <%=strNum %><br>

파라미터값 문자열+10 : <%=strNum + 10 %><br>

파라미터값 숫자+10 : <%=num + 10 %><br>


</body>

</html>