dinesh07.msc 0 Newbie Poster

404 error.requesting the resource while i click submit,
i included lib files of struts in web-inf dir in this project.
build success,
not forwarding as per code in mainpage.java.

index page(run):

    <body>
    <h1>Hello World!</h1>
    <a href="mainpage">Main page</a>
    </body>

main page:

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet mainpage</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("<form action='strapp' method='post'>");
        out.println("<input type='text' name='user'/><br>");
        out.println("<input type='submit' name='Submit it'/>");
        out.println("</form>");
        out.println("</body>");
        out.println("</html>");

success.java:

         out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet success</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet success at </h1>");
        out.println("<p>Success page</p>");
        out.println("</body>");
        out.println("</html>");

error.java:

        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet error</title>");  
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet error at </h1>");
        out.println("<p>Error page</p>");
        out.println("</body>");
        out.println("</html>");

struts-config:

        <action-mappings>
        <action path="/strapp" type="strapp">
        <forward name="success" path="/success.java"/>
        <forward name="error" path="/error.java"/>
        </action>
        </action-mappings>

strapp.java(action servlet):

         public ActionForward execute(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
        String c=(String)request.getParameter("user");
        if(c==null)
        {
        return mapping.findForward("error");
        }
        return mapping.findForward("success");
        }

web.xml:

        <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>
        <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
        </init-param>
        <init-param>
        <param-name>detail</param-name>
        <param-value>2</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
        </servlet-mapping>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.