본문 바로가기

JSP

변수를 지원하는 커스텀액션2

<%@tag pageEncoding="utf-8" %>

<%@tag body-content="empty"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

 


newMax.tag 파일작성


<%@attribute name="var" required="true" rtexprvalue="false" %>

 

<%@attribute name="num1" type="java.lang.Integer" %>

<%@attribute name="num2" type="java.lang.Integer" %>

 

<%@variable name-from-attribute="var" alias="maximum" variable-class="java.lang.Integer" scope="AT_END" %>

 

<%

    int result;

    if(num1 > num2) result = num1;

    else result = num2;

 

%>

<c:set var="maximum" value="<%=result %>"/>

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<%@taglib prefix="util" tagdir="/WEB-INF/tags"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

<h3>최대값 구하기</h3>

<util:newMax var="max" num1="${param.num1}" num2="${param.num2}"/>

최대값 : ${max}

</body>

</html>



변수의 이름이 태그 파일 안에 고정되어 있다는 단점을 해결!