๋ฐ์ํ
<%@ page import = "kr.or.ksmart.Cal" %>
์์ฉํด์ ๋ง๋ ๋ ์์ ํฉ์ ๊ตฌํ๋ ํ์ด์ง ์ฝ๋
์ ๋ ฅ ํ์ด์ง jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
%>
<h3>๋ ์๋ฅผ ์
๋ ฅํ์ธ์.</h3>
<form action="<%= request.getContextPath() %>/action.jsp" method="post">
์ซ์ 1 : <input type="number" name="oneNum"> <br/>
์ซ์ 2 : <input type="number" name="twoNum"> <br/><br/>
<input type="submit" value="์ ์กํ๊ธฐ">
</form>
</body>
</html>
java class
package kr.or.ksmart;
public class Cal {
public int sum(int one, int two) {
System.out.println(one+"<-- one๋ณ์ sum๋ฉ์๋ Cal.java");
System.out.println(two+"<-- two๋ณ์ sum๋ฉ์๋ Cal.java");
int hap = one + two;
return hap;
}
}
๊ฒฐ๊ณผ ์ถ๋ ฅ ํ์ด์ง jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import = "kr.or.ksmart.Cal" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
String oneNumber = request.getParameter("oneNum");
String twoNumber = request.getParameter("twoNum");
System.out.println(oneNumber+"๊ณผ"+twoNumber);
int oneNum = Integer.parseInt(oneNumber);
int twoNum = Integer.parseInt(twoNumber);
Cal numSum = new Cal();
int sumNum = numSum.sum(oneNum,twoNum);
%>
<h3>
<%= oneNum %> ๊ณผ <%= twoNum %> <br/>
๋ ์์ ํฉ์ <%= sumNum %> ์
๋๋ค.
</h3>
</body>
</html>
์ถ๋ ฅ ๋ด์ฉ
๋ฐ์ํ
'๊ฐ๋ฐ ์ด์ผ๊ธฐ > ์์ ๋ด์ฉ ์ ๋ฆฌ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
jsp ์ jdbc - java์ DB ์ฐ๋ (0) | 2023.07.31 |
---|---|
jsp post,GET ๋ฐฉ์์ผ๋ก ๊ฐ ๊ฐ์ ธ์ค๊ธฐ (0) | 2023.07.26 |
Java - setting, getting ์์ ๋ด์ฉ ์ ๋ฆฌ (0) | 2023.07.11 |