입력된 두 수를 더하는 jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="ex02_ok.jsp" method="post">
num1 : <input type="text" name="num1"/><br />
num2 : <input type="text" name="num2"/><br />
<input type="submit" value="전송" />
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
int num1 = 0;
int num2 = 0;
int result = 0;
String str1 = request.getParameter("num1");
String str2 = request.getParameter("num2");
num1 = Integer.parseInt(str1);
num2 = Integer.parseInt(str2);
result = num1 + num2;
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%=num1 %> + <%=num2 %> = <%=result %>
</body>
</html>
<%@ page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%> <!--익셉션이 발생했을 때 호출 --> <% response.setStatus(200); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> 숫자 포맷이
잘못되었습니다. <br /><br /> 상세 에러
메시지 : <%=exception.getMessage()%> </body> </html> <%@ page language="java"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <% response.setStatus(200); %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> 요청하신 페이지를
발견할
수
없습니다. </body> </html>
'JSP' 카테고리의 다른 글
익스프레션 언어 requestScope (0) | 2013.03.21 |
---|---|
서블릿의 라이프 사이클 (0) | 2013.03.21 |
URL 재작성 메커니즘 (0) | 2013.03.20 |
세션 (0) | 2013.03.20 |
쿠키 (0) | 2013.03.20 |