目次 |
---|
・DynaActionForm ・struts-configの例 ・Actionクラスの例 |
<%@ 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="/LoginAction"> Login画面<br ><br > <html:text property="id" size="10" maxlength="8" /> <html:text property="password" size="10" maxlength="8" /> <html:submit property="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.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="test_form" type="org.apache.struts.action.DynaActionForm"> <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.TestDynaLoginAction" name="test_form" scope="request"> <forward name="success" path="/WEB-INF/pages/login.jsp" /> </action> </action-mappings> <message-resources parameter="MessageResources"/> </struts-config>
package jp.co.confrage.action; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import jp.co.confrage.form.LoginForm; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.DynaActionForm; public class TestDynaLoginAction extends Action { public ActionForward execute(ActionMapping mapping, ActionForm _form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { DynaActionForm form = (DynaActionForm)_form; String id = (String)form.get("id"); String pass = (String)form.get("password"); return mapping.findForward("success"); } }
<%@ 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> <bean:write name="test_form" property="id" /> <bean:write name="test_form" property="password" /> </body> </html:html>