Discussions

Web tier: servlets, JSP, Web frameworks: use of struts

  1. use of struts (3 messages)

    Hello guys i want to know where i am wrong.Simply i am making helloworld in struts.plz help me where i am wrong.My error is..

    description The requested resource (/StrutsHelloWorldExample//helloWorld.jsp) is not available.

    Action class

    package com.Helloworld.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;

    import com.Helloworld.formbean.HelloWorldForm;

    public class HelloWorldAction extends Action{
        
        public ActionForward execute(ActionMapping mapping,ActionForm form,
                HttpServletRequest request,HttpServletResponse response)
        {
            HelloWorldForm helloWorldForm = (HelloWorldForm)form;
            
            helloWorldForm.setMessage("Hello ss in ur Web Example");
            return mapping.findForward("success");
        }

    }

    formbean class

    package com.Helloworld.formbean;

    import org.apache.struts.action.ActionForm;

    public class HelloWorldForm extends ActionForm{
        
        private static  final long serialVersionUID = -473562596852452021L;
        
        private String message;

        public String getMessage() {
            return message;
        }

        public void setMessage(String message) {
            this.message = message;
        }

    }

    JSP class:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Hello World</title>
    </head>
    <body>
    <html:form action="/HelloWorldForm">

    </html:form>
    </body>
    </html>

     

    stuts-config.XML

    <?xml version="1.0" encoding="ISO-8859-1" ?>

    <!DOCTYPE struts-config PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
    "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
    <struts-config>

        <form-beans>
            <!-- *******   ************ -->
            <form-bean name="helloWorldForm"
                type="com.Helloworld.formbean.HelloWorldForm" />
        </form-beans>

        <global-forwards>
            <forward name="helloWorld" path="/helloWorld.do"/>
        </global-forwards>
        
        <action-mappings>

              
            <action attribute="HelloWorldForm" input="/helloWorld.jsp"
                name="HelloWorldForm" path="/HelloWorldForm"
                scope="request" type="com.Helloworld.action.HelloWorldAction">
                
                <forward name="success" path="/helloWorld.jsp" />
            </action>
           
        </action-mappings>

        


    </struts-config>

     

    web.xml

     

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>StrutsHelloWorldExample</display-name>
     
      <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>2</load-on-startup>
     </servlet>
     
     <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
     
      <jsp-config>
        <taglib>
          <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
        </taglib>
        <taglib>
          <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>
        <taglib>
          <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
        </taglib>
        <taglib>
          <taglib-uri>/WEB-INF/struts-nested.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-nested.tld</taglib-location>
        </taglib>
        <taglib>
          <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
        </taglib>
      </jsp-config>
     
      <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
      </welcome-file-list>
    </web-app>

     

    Now can anyone plz chk it where m wrong.Why it is not getting the path...Please

    Thanks in advance

    Threaded Messages (3)

  2. use of struts[ Go to top ]

    No one is there to answer.great...

  3. form name[ Go to top ]

    The case is wrong when you reference the form name in the action...  note the capital...

  4. use of struts[ Go to top ]

    Why use Struts 1? For new apps Struts 2 is a better choice.