简体   繁体   中英

Struts 1.2 Displaying Message in JSP

I am Creating a Struts 1.2 Application.The Folder Structure is as given Below

Struts App Folder Structure

在此处输入图片说明

In the web.xml I coded in such a way that it load config from 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>

The content of struts-config.xml is as Below

<?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>

I created a User.java file src folder and forwarded a success msg as below

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");
        }
    }

The welcome.jsp file contains only a sample Welcome message inside H1 Tag

Now when i run the Struts app the page is displaying the error as below

在此处输入图片说明

Could some one help me where I am going wrong

You forgot to surround your <action-mappings> tag with the following tag element: <struts-config> .

This is how your struts-config.xml should look like:

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

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM