return (mapping.findForward("success")); }}struts_config.xml<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><!-- This is the Struts configuration file for the example application, using the proposed new syntax. -->
struts_config.xml<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><!-- This is the Struts configuration file for the example application, using the proposed new syntax. --> <struts-config> <!-- ========== Data Source Configuration =============================== --> <!-- <data-sources> <data-source> <set-property property="autoCommit" value="false"/> <set-property property="description" value="Example Data Source Configuration"/> <set-property property="driverClass" value="org.postgresql.Driver"/> <set-property property="maxCount" value="4"/> <set-property property="minCount" value="2"/> <set-property property="password" value="mypassword"/> <set-property property="url" value="jdbc:postgresql://localhost/mydatabase"/> <set-property property="user" value="myusername"/> </data-source> </data-sources> --> <!-- ========== Form Bean Definitions =================================== --> <form-beans> <!-- Logon form bean --> <form-bean name="logonForm" type="org.apache.struts.validator.DynaValidatorForm"> <form-property name="username" type="java.lang.String"/> <form-property name="password" type="java.lang.String"/> </form-bean> <!-- Subscription form bean --> <form-bean name="subscriptionForm" type="org.apache.struts.webapp.example.SubscriptionForm"/> <form-bean name="book" type="bbb.book"/> </form-beans> <!-- ========== Global Forward Definitions ============================== --> <global-forwards> <forward name="logoff" path="/logoff.do"/> <forward name="logon" path="/logon.jsp"/> <forward name="success" path="/mainMenu.jsp"/> </global-forwards> <!-- ========== Action Mapping Definitions ============================== --> <action-mappings> <!-- Edit mail subscription --> <action path="/createBook" type="bbb.createbook" attribute="book" scope="request" >
</action> <action path="/editSubscription" type="org.apache.struts.webapp.example.EditSubscriptionAction" attribute="subscriptionForm" scope="request" validate="false"> <forward name="failure" path="/mainMenu.jsp"/> <forward name="success" path="/subscription.jsp"/> </action> <!-- Process a user logoff --> <action path="/logoff" type="org.apache.struts.webapp.example.LogoffAction"> <forward name="success" path="/index.jsp"/> </action> <!-- Process a user logon --> <action path="/logon" type="org.apache.struts.webapp.example.LogonAction" name="logonForm" scope="session" input="logon"> <exception key="expired.password" type="org.apache.struts.webapp.example.ExpiredPasswordException" path="/changePassword.jsp"/> </action> <!-- Save mail subscription --> <action path="/saveSubscription" type="org.apache.struts.webapp.example.SaveSubscriptionAction" name="subscriptionForm" scope="request" input="subscription"> <forward name="subscription" path="/subscription.jsp"/> <forward name="success" path="/editRegistration.do?action=Edit"/> </action> <!-- Display the "walking tour" documentation --> <action path="/tour" forward="/tour.htm"> </action> </action-mappings> <!-- ========== Controller Configuration ================================ --> <controller> <!-- The "input" parameter on "action" elements is the name of a local or global "forward" rather than a module-relative path --> <set-property property="inputForward" value="true"/> </controller> <!-- ========== Message Resources Definitions =========================== --> <message-resources parameter="org.apache.struts.webapp.example.ApplicationResources"/> <message-resources parameter="org.apache.struts.webapp.example.AlternateApplicationResources" key="alternate"> </message-resources> <!-- ========== Plug Ins Configuration ================================== --> <plug-in className="org.apache.struts.plugins.ModuleConfigVerifier"/> <plug-in className="org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn"> <set-property property="pathname" value="/WEB-INF/database.xml"/> </plug-in> <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>web.xml<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"><web-app> <display-name>Struts Example Application</display-name> <!-- Action Servlet Configuration --> <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, /WEB-INF/struts-config-registration.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <!-- Action Servlet Mapping --> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <!-- The Welcome File List --> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- Application Tag Library Descriptor --> <taglib> <taglib-uri>/WEB-INF/app.tld</taglib-uri> <taglib-location>/WEB-INF/app.tld</taglib-location> </taglib> <!-- Struts Tag Library Descriptors --> <taglib> <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri> <taglib-location>/WEB-INF/struts-bean.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri> <taglib-location>/WEB-INF/struts-html.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri> <taglib-location>/WEB-INF/struts-logic.tld</taglib-location> </taglib></web-app>
//import org.apache.commons.beanutils.PropertyUtils;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
其他包都能用的,包应该不会引用的不对,因为我是从STRUTS提供的例子中直接复制过来的,且我做的例子很简单的,都没啥东西。
<form-beans></form-beans>
是这吧!难道还有其他地方!?》
<%@ taglib uri="/WEB-INF/app.tld" prefix="app" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html:html locale="true">
<head>
<title>BookView</title>
<html:base/>
</head>
<body bgcolor="white">
<h2>BookView</h2>
<html:form action="/createBook.do">
Title<html:text property="title"/>
<br>
<html:submit property="submit"/></html:form>
</body>
</html:html>book.javapackage bbb;
import java.util.Vector;
//import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public final class book extends ActionForm
{
private String title;
public book()
{}
public void setTitle(String title)
{
this.title=title;
}
public String getTitle()
{return this.title;}
/*public void setPages(int pages)
{this.pages=pages;}
public int getPages()
{return this.pages;}
public void addAuthor(String author)
{this.authors.add(author);}
public void removeAuthor(int p)
{this.authors.remove(p);}
public int getNumberOfAuthors()
{return this.authors.size();}*/
}createbook.javapackage bbb;import java.lang.reflect.InvocationTargetException;
import java.util.Locale;import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
//import org.apache.commons.beanutils.PropertyUtils;
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;public final class createbook extends Action
{
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
return (mapping.findForward("success"));
}}struts_config.xml<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><!--
This is the Struts configuration file for the example application,
using the proposed new syntax.
-->
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><!--
This is the Struts configuration file for the example application,
using the proposed new syntax.
-->
<struts-config>
<!-- ========== Data Source Configuration =============================== -->
<!--
<data-sources>
<data-source>
<set-property property="autoCommit"
value="false"/>
<set-property property="description"
value="Example Data Source Configuration"/>
<set-property property="driverClass"
value="org.postgresql.Driver"/>
<set-property property="maxCount"
value="4"/>
<set-property property="minCount"
value="2"/>
<set-property property="password"
value="mypassword"/>
<set-property property="url"
value="jdbc:postgresql://localhost/mydatabase"/>
<set-property property="user"
value="myusername"/>
</data-source>
</data-sources>
-->
<!-- ========== Form Bean Definitions =================================== -->
<form-beans> <!-- Logon form bean -->
<form-bean name="logonForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="username" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
</form-bean> <!-- Subscription form bean -->
<form-bean name="subscriptionForm"
type="org.apache.struts.webapp.example.SubscriptionForm"/> <form-bean name="book"
type="bbb.book"/> </form-beans>
<!-- ========== Global Forward Definitions ============================== -->
<global-forwards>
<forward name="logoff" path="/logoff.do"/>
<forward name="logon" path="/logon.jsp"/>
<forward name="success" path="/mainMenu.jsp"/>
</global-forwards>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings> <!-- Edit mail subscription -->
<action path="/createBook"
type="bbb.createbook"
attribute="book"
scope="request"
>
</action> <action path="/editSubscription"
type="org.apache.struts.webapp.example.EditSubscriptionAction"
attribute="subscriptionForm"
scope="request"
validate="false">
<forward name="failure" path="/mainMenu.jsp"/>
<forward name="success" path="/subscription.jsp"/>
</action> <!-- Process a user logoff -->
<action path="/logoff"
type="org.apache.struts.webapp.example.LogoffAction">
<forward name="success" path="/index.jsp"/>
</action> <!-- Process a user logon -->
<action path="/logon"
type="org.apache.struts.webapp.example.LogonAction"
name="logonForm"
scope="session"
input="logon">
<exception
key="expired.password"
type="org.apache.struts.webapp.example.ExpiredPasswordException"
path="/changePassword.jsp"/>
</action> <!-- Save mail subscription -->
<action path="/saveSubscription"
type="org.apache.struts.webapp.example.SaveSubscriptionAction"
name="subscriptionForm"
scope="request"
input="subscription">
<forward name="subscription" path="/subscription.jsp"/>
<forward name="success" path="/editRegistration.do?action=Edit"/>
</action>
<!-- Display the "walking tour" documentation -->
<action path="/tour"
forward="/tour.htm">
</action> </action-mappings>
<!-- ========== Controller Configuration ================================ --> <controller>
<!-- The "input" parameter on "action" elements is the name of a
local or global "forward" rather than a module-relative path -->
<set-property property="inputForward" value="true"/>
</controller>
<!-- ========== Message Resources Definitions =========================== --> <message-resources
parameter="org.apache.struts.webapp.example.ApplicationResources"/> <message-resources
parameter="org.apache.struts.webapp.example.AlternateApplicationResources"
key="alternate">
</message-resources>
<!-- ========== Plug Ins Configuration ================================== --> <plug-in className="org.apache.struts.plugins.ModuleConfigVerifier"/> <plug-in className="org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn">
<set-property property="pathname" value="/WEB-INF/database.xml"/>
</plug-in> <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>web.xml<?xml version="1.0" encoding="ISO-8859-1"?><!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"><web-app>
<display-name>Struts Example Application</display-name> <!-- Action Servlet Configuration -->
<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, /WEB-INF/struts-config-registration.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <!-- Application Tag Library Descriptor -->
<taglib>
<taglib-uri>/WEB-INF/app.tld</taglib-uri>
<taglib-location>/WEB-INF/app.tld</taglib-location>
</taglib> <!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib> <taglib>
<taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib></web-app>