잡동사니에도 사랑을

[21.10.06]elInput2.jsp / elResult2.jsp(el) 본문

JAVA_EE/EL-JSTL

[21.10.06]elInput2.jsp / elResult2.jsp(el)

luvforjunk 2021. 10. 7. 02:58
728x90
반응형

////////elInput2.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 name="calcForm" method="get" action="elResult2.jsp">
	<h3>자바클래스의 메소드를 이용해 계산</h3>
		<table border="1" cellspacing="0" cellpadding="5">
			<tr>
				<td width="50" align="center">X</td>
				<td>
					<input type="text" name="x">
				</td>
			</tr>

			<tr>
				<td width="100" align="center">Y</td>
				<td>	
					<input type="text" name="y">
				</td>
			</tr>

			<tr>
				<td colspan="2" align="center">
					<input type="submit" value="계산"> 
					<input type="reset" value="취소">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

 

 

 

////////elResult2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="luv" uri="tld" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>자바클래스의 메소드를 이용해 계산</h3>

${param['x'] } + ${param['y'] } = ${ luv:sum(param['x'], param['y']) }<br>

${param.x } * ${param.y } = ${ luv:mul(param.x, param.y) }<br>
</body>
</html>

 

 

 

////////Compute.java

package com.el;

public class Compute {
	
	public static int sum(String x, String y) { // 문자열의 합 구하기
		return Integer.parseInt(x) + Integer.parseInt(y);
	}
	public static int mul(String x, String y) { // 문자열의 합 구하기
		return Integer.parseInt(x) * Integer.parseInt(y);
		
	}
}

// static이 아니면 반드시 new를 해야하고
// static이면 바로 접근할 수 있다

 

결과창 - Input2

 

결과창 - Result2

 

728x90
반응형