728x90
2-5. Parameter(파라미터) IN / OUT 2
paraPostIn.html
<!DOCTYPE html>
<html lang="ko">
<head>
<title>HTML</title>
<meta charset="utf-8">
</head>
<body>
<form action="paraOut.jsp" method="post">
<label>사용자명<input type="text" name="userName"/></label><br>
<label>숫자1<input type="number" name="num1"/></label><br>
<label>숫자2<input type="number" name="num2"/></label>
<input type="submit"/>
</form>
</body>
</html>
paraOut.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="ch02.ex05.AddService"%>
<!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 num1Str = request.getParameter("num1");
String num2Str = request.getParameter("num2");
int num1 = Integer.parseInt(num1Str);
int num2 = Integer.parseInt(num2Str);
AddService adder = new AddService();
%>
<%=userName%>이 요청한 계산 결과는<br>
<%=num1%> + <%=num2%> = <%=adder.add(num1,num2)%>
AddService.java
public class AddService {
public int add(int num1, int num2){
return num1+num2;
}
}
728x90
'WEB > JSP' 카테고리의 다른 글
[JSP] ch02-07. Include (0) | 2017.11.13 |
---|---|
[JSP] ch02-06. Target (0) | 2017.11.09 |
[JSP] ch02-04. Parameter(파라미터) (0) | 2017.11.01 |
[JSP] ch02-03. Import (0) | 2017.11.01 |
[JSP] ch02-02. declaration (0) | 2017.11.01 |
댓글