tagSample.jsp
<%@page import="tagSample.TagForm"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="bean" uri="struts-bean" %>
<%@ taglib prefix="html" uri="struts-html" %>
<%@ taglib prefix="logic" uri="struts-logic" %>
<%@ taglib prefix="template" uri="struts-template" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% TagForm tf = (TagForm)session.getAttribute("tagForm1"); %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSPのタグサンプル</title>
</head>
<body>
<h1>JSPのタグのサンプルです1。</h1>
<html:form action="/tagSample/TagEqualAction">
<logic:equal>/<logic:notEqual>の確認<br>
値1と値2の値が同じかチェックします。<br>
値1:<html:text property="input1" />
値2:<html:text property="input2" />
<html:submit property="submit" value="比較"/>
<html:reset value="リセット"/>
<logic:present name="tagForm" property="input2">
<bean:define id="num" name="tagForm" property="input1" type="java.lang.String" />
<logic:equal name="tagForm" property="input2" value="<%=tf.getInput1()%>">
<br>値1と値2は同じ値です。
</logic:equal>
<logic:notEqual name="tagForm" property="input1" value="<%=tf.getInput2()%>">
<br> 値1と値2は異なる値です。
</logic:notEqual>
</logic:present>
</html:form>
<br>
<logic:present>/<logic:notPresent>の確認<br>
値1に値が入力されているかチェックします。<br>
<html:form action="/tagSample/TagPresentAction">
値1:<html:text property="presentValue1" />
<html:submit property="submit" value="送信"/>
<br/>
<logic:present name="tagForm" property="presentValue1">
<bean:define id="value1" name="tagForm" property="presentValue1" />
"値1"には、「<%=value1 %>」が入力されました。
</logic:present>
<logic:notPresent name="tagForm" property="presentValue1">
"値1"には、何も入力されていません。
</logic:notPresent>
</html:form>
<br>
<html:form action="/tagSample/TagGreaterAction">
<logic:greaterEqual>/<logic:greaterThan>の確認<br>
値1と値2を比較します。<br>
値1:
<html:select property="selectInput1">
<html:options name="tagForm" property="selectlist" labelProperty="selectlist" />
</html:select>
値2:
<html:select property="selectInput2">
<html:options name="tagForm" property="selectlist" labelProperty="selectlist" />
</html:select>
<html:submit property="submit" value="比較"/>
<logic:present name="tagForm" property="selectInput1">
<bean:define id="selectInput2" name="tagForm" property="selectInput2" type="java.lang.String" />
<logic:greaterThan name="tagForm" property="selectInput1" value="<%=selectInput2%>">
<br>値1:<bean:write name="tagForm" property="selectInput1"/>は値2:<bean:write name="tagForm" property="selectInput2"/>より大きい値です。
</logic:greaterThan>
<logic:greaterEqual name="tagForm" property="selectInput1" value="<%=selectInput2%>">
<br>値1:<bean:write name="tagForm" property="selectInput1"/>は値2:<bean:write name="tagForm" property="selectInput2"/>以上の値です。
</logic:greaterEqual>
<logic:lessThan name="tagForm" property="selectInput1" value="<%=selectInput2%>">
<br>値1は値2より大きい値にしてください。
</logic:lessThan>
</logic:present>
</html:form>
<br>
<html:form action="/tagSample/TagLessAction">
<logic:lessEqual>/<logic:lessThan>の確認<br>
値1と値2を比較します。<br>
値1:
<html:select property="selectInput3">
<html:options name="tagForm" property="selectlist" labelProperty="selectlist" />
</html:select>
値2:
<html:select property="selectInput4">
<html:options name="tagForm" property="selectlist" labelProperty="selectlist" />
</html:select>
<html:submit property="submit" value="比較"/>
<logic:present name="tagForm" property="selectInput3">
<bean:define id="selectInput4" name="tagForm" property="selectInput4" type="java.lang.String" />
<logic:lessThan name="tagForm" property="selectInput3" value="<%=selectInput4%>">
<br>値1:<bean:write name="tagForm" property="selectInput3"/>は値2:<%=selectInput4%>より小さい値です。
</logic:lessThan>
<logic:lessEqual name="tagForm" property="selectInput3" value="<%=selectInput4%>">
<br>値1:<bean:write name="tagForm" property="selectInput3"/>は値2:<%=selectInput4%>以下の値です。
</logic:lessEqual>
<logic:greaterThan name="tagForm" property="selectInput3" value="<%=selectInput4%>">
<br>値1は値2より小さい値にしてください。
</logic:greaterThan>
</logic:present>
</html:form>
<br>
<html:form action="/tagSample/TagMatchAction">
<logic:match>/<logic:notMatch>の確認<br>
値1に値2が含まれているかチェックします。<br>
<div style="display: flex; align-items: start;">
値1:<html:textarea property="matchInput1" rows="3" cols="31" /><br>
</div>
値2:<html:text property="matchInput2" size="40" />
<html:submit property="submit" value="比較"/>
<logic:present name="tagForm" property="matchInput1">
<bean:define id="matchInput2" name="tagForm" property="matchInput2" type="java.lang.String" />
<logic:match name="tagForm" property="matchInput1" value="<%=matchInput2%>">
<br>値1:<bean:write name="tagForm" property="matchInput1"/>は値2:<bean:write name="tagForm" property="matchInput2"/>を含んでいます。
</logic:match>
<logic:notMatch name="tagForm" property="matchInput1" value="<%=matchInput2%>">
<br>値1:<bean:write name="tagForm" property="matchInput1"/>は値2:<bean:write name="tagForm" property="matchInput2"/>を含んでいません。
</logic:notMatch>
</logic:present>
</html:form>
<br>
<html:form action="/tagSample/TagIterateAction">
<logic:logic:iterate>の確認<br>
String[]とListとMapとSetの配列を表示します。
<html:submit property="submit" value="表示"/>
<logic:present name="stringData">
<hr>
<bean:size name="stringData" id="strSize" />
String[]型の配列を表示する <bean:write name="strSize" />件表示するよ!<br>
<logic:iterate id="data" name="stringData" >
<bean:write name="data" /> <br>
</logic:iterate>
</logic:present>
<logic:present name="listData">
<hr>
<bean:size name="listData" id="listSize" />
List型の配列を表示する <bean:write name="listSize" />件表示するよ!<br>
<logic:iterate id="data" name="listData" >
<bean:write name="data" /> <br>
</logic:iterate>
</logic:present>
<logic:present name="mapData">
<hr>
<bean:size name="mapData" id="mapSize" />
Map型のKeyとvalueをそれぞれ表示する <bean:write name="mapSize" />件表示するよ!<br>
<logic:iterate id="data" name="mapData" >
<bean:write name="data" property="key" />:<bean:write name="data" property="value" /><br>
</logic:iterate>
</logic:present>
<logic:present name="setData">
<hr>
<bean:size name="setData" id="setSize" />
Set型の配列を表示する <bean:write name="setSize" />件表示するよ!<br>
<logic:iterate id="data" name="setData" >
<bean:write name="data" /><br>
</logic:iterate>
</logic:present>
<hr>
</html:form>
<html:radio name="tagForm" property="radio" value="0"/>西
<html:radio name="tagForm" property="radio" value="1"/>東<br>
チェックボックス1:<html:multibox name="tagForm" property="checkbox" value="1"/><br>
チェックボックス2:<html:checkbox name="tagForm" property="checkbox"/>
</body>
</html>
TagEqualAction.java
package tagSample;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class TagEqualAction extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest req, HttpServletResponse res) {
TagForm tagForm = (TagForm) form;
System.out.println("equalタグ用のForm値1:" + tagForm.getInput1());
System.out.println("equalタグ用のForm値2:" + tagForm.getInput2());
req.getSession().setAttribute("tagForm1", tagForm);
return (mapping.findForward("SUCCESS"));
}
}
|