웹 프로그래밍(풀스택-->java)/웹프로그래밍(백엔드-->java)
41. Jsp 중고급 - 3. Expression Language 활용법 2
백엔드개발자0107
2021. 12. 9. 10:51
자 오늘 우리가 할것은 지난시간에 EL태그에 대해서 간단한게 설명하였다.
EL은 중괄호 열고 닫고 쓰고 그 안에 request객체와 session객체를 이용하여 어트리뷰트를 이용하여 출력할수 있는것과
파리미터 태그같이 el 에서 자연스럽게 사용할수 있는 내장객체등이 있었다.
그 내장객체는 연산기호 크고 작다 등을 사용할수 있었다.
ElCul.jsp
<%--
Created by IntelliJ IDEA.
User: jeongdahyeon
Date: 2021/12/09
Time: 10:12 AM
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<center>
<h2>계산기</h2>
<form action="ElCul.jsp" method="post">
<table width="400">
<tr height="40">
<td align="center" width="100">
<input type="text" name="exp1">
</td>
<td align="center" width="50">
<select name="exp2">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</td>
<td align="center" width="100">
<input type="text" name="exp3">
</td>
<td align="center" width="20">
=
</td>
<td align="center" width="100">
<%
String exp2 = request.getParameter("exp2");
//nullPointerException이 나왔으니 null 처리를 해주도록 한다.
if(exp2==null){
exp2 = "+";
}
//예전 방식(모델1)방식이었다면
if(exp2.equals("+")){
%>
<input type="text" name="ex4" value="${param.exp1 + param.exp3}">
<%
}
if(exp2.equals("-")){
%>
<input type="text" name="ex4" value="${param.exp1 - param.exp3}">
<%
}
%>
<%
if(exp2.equals("*")){
%>
<input type="text" name="ex4" value="${param.exp1 * param.exp3}">
<%
}
%>
<%
if(exp2.equals("/")){
%>
<input type="text" name="ex4" value="${param.exp1 / param.exp3}">
<%
}
%>
</td>
<td align="center" width="100">
<input type="submit" value="결과보기">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>