๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๊ฐœ๋ฐœ ์ด์•ผ๊ธฐ/์ˆ˜์—… ๋‚ด์šฉ ์ •๋ฆฌ

Java - jsp๋กœ ๋‹ค๋ฅธ ํด๋ž˜์Šค import ํ•˜๊ธฐ

by 0_0๐Ÿ–ค 2023. 7. 27.
๋ฐ˜์‘ํ˜•

 

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

 

 

์ถœ๋ ฅ ๋‚ด์šฉ

 

์ž…๋ ฅ ํŽ˜์ด์ง€

 

์ถœ๋ ฅ ํŽ˜์ด์ง€

 

 

 

๋ฐ˜์‘ํ˜•