0

我有一个带有以下 web.xml 和 struts-config.xml 的 Struts 1.2 应用程序

web.xml

    <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</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

struts-config.xml

<?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>
    <form-beans>
            <form-bean name="Welcome"
                type="com.mugil.tutor.action.Sample" />
        </form-beans>
    <action-mappings>
        <action path="/Welcome" name="Welcome"  type="com.mugil.tutor.action.Sample">
            <forward name="success" path="/welcome.jsp"/>
        </action>
    </action-mappings>
    </struts-config>

Files的目录结构如下图

在此处输入图像描述

我想在welcome.jsp 中显示欢迎消息。这应该在我收到来自Sample.java 的成功消息后发生

示例.java

package com.mugil.tutor.action;

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.ActionForward;
import org.apache.struts.action.ActionMapping;

public class Sample extends Action
{
     public ActionForward execute(ActionMapping mapping, ActionForm form,
                HttpServletRequest request, HttpServletResponse response)
                throws Exception 
    {
         String target = "success"; 
         return mapping.findForward(target);
    }
}

欢迎.jsp

<title>Insert title here</title>
</head>
<body>
    <h1>Welcome to Struts 1.2</h1>
</body>
</html>

我不知道我哪里出错了。当我尝试修复一个错误消息时,它会显示不同的错误消息。

4

1 回答 1

1

我认为这是因为您已将 映射ActionServlet到 url 模式/*。我不认为 Struts 1 处理“无扩展”的 url,它会干扰/welcome.jsp. 尝试将 url 模式更改为*.do或其他一些后缀。

于 2013-05-07T12:33:34.287 回答