dispatchAction 的作用是一个action可以处理不同的请求
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for Add_UpdateForm form</title>
</head>
<body>
<h1>添加页面</h1>
<html:form action="/add_Update.do?
methods=add">
password : <html:password property="password"/><html:errors property="password"/><br/>
name : <html:text property="name"/><html:errors property="name"/><br/>
<html:submit /><html:cancel/>
</html:form>
</body>
</html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<title>JSP for Add_UpdateForm form</title>
</head>
<body>
<h1>修改页面</h1>
<html:form action="/add_Update.do?
methods=update">
password : <html:password property="password"/><html:errors property="password"/><br/>
name : <html:text property="name"/><html:errors property="name"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
</html>
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111
package com.yourcompany.struts.action;
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 Add_UpdateAction extends DispatchAction {
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("addOk");
}
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
return mapping.findForward("updateOk");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<data-sources />
<form-beans >
<form-bean name="add_UpdateForm" type="com.yourcompany.struts.form.Add_UpdateForm" />
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="add_UpdateForm"
input="/add.jsp"
name="add_UpdateForm"
parameter="methods"
path="/add_Update"
scope="request"
type="com.yourcompany.struts.action.Add_UpdateAction">
<forward name="addOk" path="/addOk.jsp" />
<forward name="updateOk" path="/updateOk.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>
posted on 2008-03-08 23:32
Crying 阅读(315)
评论(0) 编辑 收藏 所属分类:
Jsp+Struts