<%@ page language="java" contentType="text/html; charset=Shift_JIS"
pageEncoding="Shift_JIS"%>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/lib/struts-bean.tld" prefix="bean"%>
<html:html locale="true">
<bean:parameter id="result" name="age" />
<body>
<h1>正常に遷移しました</h1>
あなたの年齢は<bean:write name="result" />です。
</body>
</html:html>
<%@ page language="java" contentType="text/html; charset=Shift_JIS"
pageEncoding="Shift_JIS"%>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<html:html locale="true">
<body>
<h1>StrutsValidator(サーバーサイド)を使った検証</h1>
<html:errors />
年齢を入力して下さい。(0以上150以下の整数で入力)
<html:form action="/CheckAge2">
年齢<html:text property="age" />
<html:errors property="age" />
<html:submit value="報告" />
</html:form>
</body>
</html:html>
pageEncoding="Shift_JIS"%>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<html:html locale="true">
<body>
<h1>StrutsValidator(サーバーサイド)を使った検証</h1>
<html:errors />
年齢を入力して下さい。(0以上150以下の整数で入力)
<html:form action="/CheckAge2">
年齢<html:text property="age" />
<html:errors property="age" />
<html:submit value="報告" />
</html:form>
</body>
</html:html>
<%@ page language="java" contentType="text/html; charset=Shift_JIS"
pageEncoding="Shift_JIS"%>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<html:html locale="true">
<body>
<h1>validate()メソッドを使った検証</h1>
<html:errors />
年齢を入力して下さい。(0以上150以下の整数で入力)
<html:form action="/CheckAge">
年齢<html:text property="age" />
<html:errors property="age" />
<html:submit value="報告" />
</html:form>
</body>
</html:html>
pageEncoding="Shift_JIS"%>
<%@ taglib uri="/WEB-INF/lib/struts-html.tld" prefix="html"%>
<html:html locale="true">
<body>
<h1>validate()メソッドを使った検証</h1>
<html:errors />
年齢を入力して下さい。(0以上150以下の整数で入力)
<html:form action="/CheckAge">
年齢<html:text property="age" />
<html:errors property="age" />
<html:submit value="報告" />
</html:form>
</body>
</html:html>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="CheckAgeForm" type="form.CheckAgeForm"/>
<form-bean name="CheckAgeForm2" type="form.CheckAgeForm"/>
<form-bean name="CheckAgeForm3" type="org.apache.struts.validator.DynaValidatorForm"/>
</form-beans>
<action-mappings>
<action path="/CheckAge" name="CheckAgeForm" type="action.CheckAgeAction" validate="true" input="/view/input1.jsp">
<forward name="checked" path="/view/AgeChecked.jsp"/>
</action>
<action path="/CheckAge2" name="CheckAgeForm2" type="action.CheckAgeAction" validate="true" input="/view/input2.jsp">
<forward name="checked" path="/view/AgeChecked.jsp"/>
</action>
<action path="/CheckAge3" name="CheckAgeForm3" type="org.apache.struts.actions.ForwardAction" validate="true" input="/view/input3.jsp" parameter="/view/AgeChecked.jsp">
</action>
</action-mappings>
<controller/>
<message-resources parameter="Message_jp"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="CheckAgeForm" type="form.CheckAgeForm"/>
<form-bean name="CheckAgeForm2" type="form.CheckAgeForm"/>
<form-bean name="CheckAgeForm3" type="org.apache.struts.validator.DynaValidatorForm"/>
</form-beans>
<action-mappings>
<action path="/CheckAge" name="CheckAgeForm" type="action.CheckAgeAction" validate="true" input="/view/input1.jsp">
<forward name="checked" path="/view/AgeChecked.jsp"/>
</action>
<action path="/CheckAge2" name="CheckAgeForm2" type="action.CheckAgeAction" validate="true" input="/view/input2.jsp">
<forward name="checked" path="/view/AgeChecked.jsp"/>
</action>
<action path="/CheckAge3" name="CheckAgeForm3" type="org.apache.struts.actions.ForwardAction" validate="true" input="/view/input3.jsp" parameter="/view/AgeChecked.jsp">
</action>
</action-mappings>
<controller/>
<message-resources parameter="Message_jp"/>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
error.age.range=\u5E74\u9F62\u306E\u7BC4\u56F2\u306F0\u6B73\u4EE5\u4E0A150\u6B73\u4EE5\u4E0B\u306B\u8A2D\u5B9A\u3057\u3066\u304F\u3060\u3055\u3044
error.age.notint=\u5E74\u9F62\u306F\u6574\u6570\u3067\u5165\u529B\u3057\u3066\u4E0B\u3055\u3044
error.age.required=\u5E74\u9F62\u3092\u5165\u529B\u3057\u3066\u4E0B\u3055\u3044\u3002
errors.prefix=<font color\="\#ff0000">
errors.suffix=</font><br>
error.age.notint=\u5E74\u9F62\u306F\u6574\u6570\u3067\u5165\u529B\u3057\u3066\u4E0B\u3055\u3044
error.age.required=\u5E74\u9F62\u3092\u5165\u529B\u3057\u3066\u4E0B\u3055\u3044\u3002
errors.prefix=<font color\="\#ff0000">
errors.suffix=</font><br>
package action;
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 CheckAgeAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("checked");
}
}
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 CheckAgeAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
return mapping.findForward("checked");
}
}
package form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.sun.org.apache.bcel.internal.generic.RETURN;
public class CheckAgeForm extends ActionForm {
private int age_;
public void setAge_(int age_) {
this.age_ = age_;
}
public int getAge_() {
return age_;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
try {
String ageString = request.getParameter("age");
if (ageString == null || " ".equals(ageString)) {
errors.add("age", new ActionMessage("error.age.required"));
} else {
int age = Integer.parseInt(ageString);
if (age < 0 || 150 < age) {
errors.add("age", new ActionMessage("error.age.range"));
}
}
} catch (NumberFormatException ex) {
errors.add("age", new ActionMessage("error.age.notint"));
}
return errors;
}
}
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import com.sun.org.apache.bcel.internal.generic.RETURN;
public class CheckAgeForm extends ActionForm {
private int age_;
public void setAge_(int age_) {
this.age_ = age_;
}
public int getAge_() {
return age_;
}
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
try {
String ageString = request.getParameter("age");
if (ageString == null || " ".equals(ageString)) {
errors.add("age", new ActionMessage("error.age.required"));
} else {
int age = Integer.parseInt(ageString);
if (age < 0 || 150 < age) {
errors.add("age", new ActionMessage("error.age.range"));
}
}
} catch (NumberFormatException ex) {
errors.add("age", new ActionMessage("error.age.notint"));
}
return errors;
}
}
<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="loginForm" type="form.LoginForm"/>
</form-beans>
<action-mappings>
<action name="loginForm" type="action.LoginAction" path="/login" scope="request">
<forward name="success" path="/view/success.jsp"/>
</action>
</action-mappings>
</struts-config>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="loginForm" type="form.LoginForm"/>
</form-beans>
<action-mappings>
<action name="loginForm" type="action.LoginAction" path="/login" scope="request">
<forward name="success" path="/view/success.jsp"/>
</action>
</action-mappings>
</struts-config>
<?xml version="1.0" encoding="Shift_JIS"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<filter>
<filter-name>
EncodeFilter
</filter-name>
<filter-class>
filters.SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>
encoding
</param-name>
<param-value>
Shift_JIS
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>
EncodeFilter
</filter-name>
<url-pattern>
/*
</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>
action
</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>
config
</param-name>
<param-value>
/WEB-INF/struts-config.xml
</param-value>
</init-param>
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>
action
</servlet-name>
<url-pattern>
*.do
</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>view/loginForm.html</welcome-file>
</welcome-file-list>
</web-app>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<filter>
<filter-name>
EncodeFilter
</filter-name>
<filter-class>
filters.SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>
encoding
</param-name>
<param-value>
Shift_JIS
</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>
EncodeFilter
</filter-name>
<url-pattern>
/*
</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>
action
</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>
config
</param-name>
<param-value>
/WEB-INF/struts-config.xml
</param-value>
</init-param>
<load-on-startup>
1
</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>
action
</servlet-name>
<url-pattern>
*.do
</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>view/loginForm.html</welcome-file>
</welcome-file-list>
</web-app>
<%@ page language="java" contentType="text/html; charset=Shift_JIS"
pageEncoding="Shift_JIS"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>ログイン結果</title>
</head>
<body>
<%= (String)request.getAttribute("message") %>
</body>
</html>
pageEncoding="Shift_JIS"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>ログイン結果</title>
</head>
<body>
<%= (String)request.getAttribute("message") %>
</body>
</html>
