Java Beginner
Java Beginner

Reputation: 1655

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

enter image description here

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

enter image description here

Could some one help me where I am going wrong

Upvotes: 0

Views: 1242

Answers (1)

Buhake Sindi
Buhake Sindi

Reputation: 89199

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.

Upvotes: 1

Related Questions