| 目次 |
|---|
|
・DispatchAction ・index.jsp ・ActionForm ・struts-config.xml |

package jp.co.confrage.action;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
public class LoginDispatchAction extends DispatchAction {
public ActionForward exec(ActionMapping mapping, ActionForm _form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
return mapping.findForward("success1");
}
public ActionForward cancel(ActionMapping mapping, ActionForm _form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
return mapping.findForward("success2");
}
}
<%@ page contentType="text/html; charset=Windows-31J" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<html:html>
<head>
<title>サンプルログイン</title>
<meta http-equiv="Content-Type"
content="text/html; charset=Windows-31J">
</head>
<body>
<html:form action="/dispatch_form">
Login画面<br /><br />
<html:text property="id" size="10" maxlength="8" />
<html:text property="password" size="10" maxlength="8" />
<html:submit property="dispatch" value="exec" >実行</html:submit>
<html:submit property="dispatch" value="cancel" >取消</html:submit>
</html:form>
</body>
</html:html>
package jp.co.confrage.form;
import org.apache.struts.action.ActionForm;
public class LoginDispatchForm extends ActionForm{
private String id = null;
private String password = null;
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
}
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<form-bean name="dispatchform" type="jp.co.confrage.form.LoginDispatchForm">
<form-property name="id" type="java.lang.String" initial="id" />
<form-property name="password" type="java.lang.String" initial="pass" />
</form-bean>
</form-beans>
<action-mappings>
<action path="/sample_form"
type="jp.co.confrage.action.TestValidatorLoginAction"
name="test_form"
scope="request"
input="/WEB-INF/pages/error.jsp">
<forward name="success" path="/WEB-INF/pages/login.jsp" />
</action>
<action path="/dispatch_form"
type="jp.co.confrage.action.LoginDispatchAction"
parameter="dispatch"
name="dispatchform"
input="/WEB-INF/pages/error.jsp">
<forward name="success1" path="/WEB-INF/pages/login2.jsp" />
<forward name="success2" path="/WEB-INF/pages/login3.jsp" />
</action>
</action-mappings>
<message-resources parameter="MessageResources"/>
</struts-config>

