好的home.jsp用于输入数据页面<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Home</title>
    </head>
    <body>        <h1>Home</h1>
        <html:link action="/home">home</html:link>
        
        <html:errors /> 
        <html:form action="NewStrutsAction">
            <table border="0">
                <thead>
                    <tr>
                        <th><bean:message key="login.name" /></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><html:text property="name" /></td>
                    </tr>
                </tbody>
            </table>
            <html:submit/>
            <html:reset/>
            <html:cancel/>
        </html:form>
                <html:link action="/link">links</html:link>
    </body>
</html>
struts-config.xml<?xml version="1.0" encoding="ISO-8859-1" ?><!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="NewStrutsActionForm" type="com.myapp.struts.NewStrutsActionForm"/>
    
    </form-beans>
    
    <global-exceptions>
    
    </global-exceptions>    <global-forwards>
        <forward name="welcome"  path="/Welcome.s"/>
    </global-forwards>    <action-mappings>
        <action input="/home.jsp" name="NewStrutsActionForm" path="/NewStrutsAction" scope="session" type="com.myapp.struts.NewStrutsAction">
            <forward name="show"  path="/show.jsp"/>
            <forward name="cancel" path="/cancel.jsp"/>
            
        </action>
        <action forward="/homepage.jsp" path="/home"/>
        <action forward="/link.jsp" path="/link"/>
        <action path="/Welcome" forward="/welcomeStruts.jsp"/>
    </action-mappings>
    
    <controller processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>    <message-resources parameter="com/myapp/struts/ApplicationResource"/>    
    
    <!-- ========================= Tiles plugin ===============================-->
    <!--
    This plugin initialize Tiles definition factory. This later can takes some
    parameters explained here after. The plugin first read parameters from
    web.xml, thenoverload them with parameters defined here. All parameters
    are optional.
    The plugin should be declared in each struts-config file.
    - definitions-config: (optional)
    Specify configuration file names. There can be several comma
    separated file names (default: ?? )
    - moduleAware: (optional - struts1.1)
    Specify if the Tiles definition factory is module aware. If true
    (default), there will be one factory for each Struts module.
    If false, there will be one common factory for all module. In this
    later case, it is still needed to declare one plugin per module.
    The factory will be initialized with parameters found in the first
    initialized plugin (generally the one associated with the default
    module).
    true : One factory per module. (default)
    false : one single shared factory for all modules
    - definitions-parser-validate: (optional)
    Specify if xml parser should validate the Tiles configuration file.
    true : validate. DTD should be specified in file header (default)
    false : no validation    Paths found in Tiles definitions are relative to the main context.
    -->
    <plug-in className="org.apache.struts.tiles.TilesPlugin" >
        <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />      
        <set-property property="moduleAware" value="true" />
    </plug-in>
    
    <!-- ========================= Validator plugin ================================= -->
    <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>
NewStrutsActionForm/*
 * NewStrutsActionForm.java
 *
 * Created on 2006年11月6日, 下午8:31
 */package com.myapp.struts;import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;/**
 *
 * @author Administrator
 * @version
 */public class NewStrutsActionForm extends org.apache.struts.action.ActionForm {
    
    private String name;
    
    private int number;
    
    /**
     * @return
     */
    public String getName() {
        return name;
    }
    
    /**
     * @param string
     */
    public void setName(String string) {
        name = string;
    }
    
    /**
     * @return
     */
    public int getNumber() {
        return number;
    }
    
    /**
     * @param i
     */
    public void setNumber(int i) {
        number = i;
    }
    
    /**
     *
     */
    public NewStrutsActionForm() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        ActionErrors errors = new ActionErrors();
        if (getName() == null || getName().length() < 1) {
            errors.add("name", new ActionMessage("error.name.required"));
            // TODO: add 'error.name.required' key to your resources
        }
        return errors;
    }
}
NewStrutsAction/*
 * NewStrutsAction.java
 *
 * Created on 2006年11月6日, 下午8:34
 */package com.myapp.struts;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.ActionMapping;
import org.apache.struts.action.ActionForward;
/**
 *
 * @author Administrator
 * @version
 */public class NewStrutsAction extends Action {
    
    /* forward name="success" path="" */
    private final static String SUCCESS = "success";
    private final static String SHOW = "show";
    private final static String CANCEL = "cancel";
    /**
     * This is the action called from the Struts framework.
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        if (isCancelled(request)){
            return mapping.findForward(CANCEL);
        }
        return mapping.findForward(SHOW);
        
    }
}

解决方案 »

  1.   

    show.jsp用于显示输入信息。<%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <jsp:useBean id="data" class="com.myapp.struts.NewStrutsActionForm" scope="session"/>
    <%--
    The taglib directive below imports the JSTL library. If you uncomment it,
    you must also add the JSTL library to the project. The Add Library... action
    on Libraries node in Projects view can be used to add the JSTL 1.1 library.
    --%>
    <%--
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
    --%><!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=UTF-8">
            <title>Show</title>
            <h1>Show</h1>
            <table border="0">
                <thead>
                    <tr>
                        <th><jsp:getProperty name="data" property="name"/></th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td></td>
                    </tr>
                </tbody>
            </table>    </head>
        <body>
        
            <%--
            This example uses JSTL, uncomment the taglib directive above.
            To test, display the page like this: index.jsp?sayHello=true&name=Murphy
            --%>
            <%--
            <c:if test="${param.sayHello}">
            <!-- Let's welcome the user ${param.name} -->
            Hello ${param.name}!
            </c:if>
            --%>
        
        </body>
    </html>
    用netbeans做的
      

  2.   

    public ActionForward execute(ActionMapping mapping, ActionForm  form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception {
            if (isCancelled(request)){
                return mapping.findForward(CANCEL);
            }
            return mapping.findForward(SHOW);
    里的CANCEL改为cancel,SHOW改为show试试!
      

  3.   

    CANCEL改为cancel,SHOW改为show不行的,前面有这几个定义
        private final static String SUCCESS = "success";
        private final static String SHOW = "show";
        private final static String CANCEL = "cancel";
    然后struts-config.xml中show,cancel都配置过相对应的页面了