Struts 1.2在JSP中显示消息

时间:2013-05-08 05:50:30

标签: java xml struts struts-1

我正在创建一个Struts 1.2应用程序。文件夹结构如下所示

Struts App文件夹结构

enter image description here

在web.xml中,我编写的方式是从struts-config.xml加载配置

<display-name>Bean</display-name>
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <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>

struts-config.xml的内容如下

<?xml version="1.0" encoding="UTF-8"?>
<action-mappings>
<action path="/User" type="com.mugil.action.User">
<forward name="success" path="/DisplayUser.jsp"/>
</action>
</action-mappings>

我创建了一个User.java文件src文件夹并转发成功消息,如下所示

package com.mugil.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 User extends Action 
    {   

        public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 
        {               
            return mapping.findForward("success");
        }
    }

welcome.jsp文件仅包含H1 Tag

中的示例欢迎消息

现在,当我运行Struts应用程序时,页面显示如下错误

enter image description here

有人可以帮助我解决我的错误

1 个答案:

答案 0 :(得分:1)

您忘记使用以下标记元素包围<action-mappings>标记:<struts-config>

这就是struts-config.xml应该是这样的:

<struts-config>
    <action-mappings>
        <action path="/User" type="com.mugil.action.User">
            <forward name="success" path="/DisplayUser.jsp"/>
        </action>
    </action-mappings>
</struts-config>

我希望这会有所帮助。