이클립스에서 작성함
클래스명 : myForm1.jsp
<?xml version="1.0" encoding="EUC-KR" ?>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
<title>Insert title here</title>
</head>
<body>
<form action="myForm2.jsp" method="post">
<!--action은 서버 쪽 주소(jsp로 구성), 여기에서는 html에 보냄-->
<table>
<tr>
<td>숫자를 입력하세요</td>
<td>
<input type="number" name="num1" id="num1">
<!-- 서버에서는 name으로, 자바스크립트는 id로 인식하므로 둘의 이름을 같게 명시해야 한다-->
</td>
</tr>
<tr>
<td>숫자를 입력하세요</td>
<td><input type="number" name="num2" id="num2"></td>
</tr>
<tr>
<td colspan="2"></td><!--컬럼 2칸 합치기-->
<td><input type="submit" value="전송"></td>
</tr>
</table>
</form>
</body>
</html>
클래스명: myForm2.jsp
<?xml version="1.0" encoding="EUC-KR" ?>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR" />
<title>Insert title here</title>
</head>
<body>
<%
String num1 = request.getParameter("num1");
String num2 = request.getParameter("num2");
int num3 = Integer.parseInt(num1);
int num4 = Integer.parseInt(num2);
out.println("첫번째 값 : " + num3);
%>
<br/>
<%out.println("두번째 값 : " + num4);%>
<br/>
<%out.println("합 : " + (num3+num4));%>
</body>
</html>
두번째 값 : 456
합 : 579
'programing > JSP' 카테고리의 다른 글
MySQL 에러 - Several ports (8005, 8080, 8009) required by Tomcat v7.0 Server at localhost are already in use (0) | 2018.03.10 |
---|---|
JSP - 구구단 출력하기 (0) | 2018.03.08 |
아파치 실행 법 (0) | 2018.03.08 |
JSP - 웹 양식 만들기 (0) | 2018.02.23 |
JSP - 톰캣 설치하기 (0) | 2018.02.22 |