Struts newbie question

Discussion in 'Java' started by in_dv, Nov 8, 2006.

  1. in_dv

    in_dv Guest

    Hello All,

    I am a newbie to struts. I am trying to get a simple example working
    which I found on jakarta struts tutorial.

    When I click on a link, I expect it to transfer to TestAction.jsp page
    , but I can see it changes to TestAction.do and I get "Page Cannot be
    found" HTTP 404 error.

    Followign are the entries in struts-config.xml file

    <action
    path="/TestAction"
    type="devika.TestAction">
    <forward name="testAction" path="/TestAction.jsp"/>
    </action>

    following is entry in .jsp file

    <html:link page="/TestAction.do">Test the Action</html:link>

    Kindly please help me

    D
     
    in_dv, Nov 8, 2006
    #1
    1. Advertising

  2. in_dv

    Tim Slattery Guest

    "in_dv" <> wrote:

    >Hello All,
    >
    >I am a newbie to struts. I am trying to get a simple example working
    >which I found on jakarta struts tutorial.
    >
    >When I click on a link, I expect it to transfer to TestAction.jsp page
    >, but I can see it changes to TestAction.do and I get "Page Cannot be
    >found" HTTP 404 error.
    >
    >Followign are the entries in struts-config.xml file
    >
    ><action
    > path="/TestAction"
    > type="devika.TestAction">
    > <forward name="testAction" path="/TestAction.jsp"/>
    > </action>
    >
    >following is entry in .jsp file
    >
    ><html:link page="/TestAction.do">Test the Action</html:link>


    That link causes the Struts front end to search the struts-config.xml
    file and find the "action" you've reproduced above. That "action"
    element tells it to transfer control to "devika.TestAction.class".
    Presumably that class will eventually pass control to the
    TestAction.jsp page (by coding something like:

    mapping.findForward("testAction");

    --
    Tim Slattery
     
    Tim Slattery, Nov 8, 2006
    #2
    1. Advertising

  3. in_dv

    Guest

    Your case is different in the forward and Struts Config.


    in_dv wrote:
    > Hello All,
    >
    > I am a newbie to struts. I am trying to get a simple example working
    > which I found on jakarta struts tutorial.
    >
    > When I click on a link, I expect it to transfer to TestAction.jsp page
    > , but I can see it changes to TestAction.do and I get "Page Cannot be
    > found" HTTP 404 error.
    >
    > Followign are the entries in struts-config.xml file
    >
    > <action
    > path="/TestAction"
    > type="devika.TestAction">
    > <forward name="testAction" path="/TestAction.jsp"/>
    > </action>
    >
    > following is entry in .jsp file
    >
    > <html:link page="/TestAction.do">Test the Action</html:link>
    >
    > Kindly please help me
    >
    > D
     
    , Nov 8, 2006
    #3
  4. in_dv

    in_dv Guest

    Thx for the reply. Do I need to keep the same case for forward and
    struts config?

    wrote:
    > Your case is different in the forward and Struts Config.
    >
    >
    > in_dv wrote:
    > > Hello All,
    > >
    > > I am a newbie to struts. I am trying to get a simple example working
    > > which I found on jakarta struts tutorial.
    > >
    > > When I click on a link, I expect it to transfer to TestAction.jsp page
    > > , but I can see it changes to TestAction.do and I get "Page Cannot be
    > > found" HTTP 404 error.
    > >
    > > Followign are the entries in struts-config.xml file
    > >
    > > <action
    > > path="/TestAction"
    > > type="devika.TestAction">
    > > <forward name="testAction" path="/TestAction.jsp"/>
    > > </action>
    > >
    > > following is entry in .jsp file
    > >
    > > <html:link page="/TestAction.do">Test the Action</html:link>
    > >
    > > Kindly please help me
    > >
    > > D
     
    in_dv, Nov 8, 2006
    #4
  5. in_dv

    in_dv Guest

    Thank you very much for your reply.
    I am pasting the code for TestAction.java file below

    /////////////////////////

    package devika;

    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 TestAction extends Action
    {
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) throws Exception{
    return mapping.findForward("testAction");
    }
    }

    //////////////////////////////////

    Then why m i getting page cannot be diplayed error ?
    Tim Slattery wrote:
    > "in_dv" <> wrote:
    >
    > >Hello All,
    > >
    > >I am a newbie to struts. I am trying to get a simple example working
    > >which I found on jakarta struts tutorial.
    > >
    > >When I click on a link, I expect it to transfer to TestAction.jsp page
    > >, but I can see it changes to TestAction.do and I get "Page Cannot be
    > >found" HTTP 404 error.
    > >
    > >Followign are the entries in struts-config.xml file
    > >
    > ><action
    > > path="/TestAction"
    > > type="devika.TestAction">
    > > <forward name="testAction" path="/TestAction.jsp"/>
    > > </action>
    > >
    > >following is entry in .jsp file
    > >
    > ><html:link page="/TestAction.do">Test the Action</html:link>

    >
    > That link causes the Struts front end to search the struts-config.xml
    > file and find the "action" you've reproduced above. That "action"
    > element tells it to transfer control to "devika.TestAction.class".
    > Presumably that class will eventually pass control to the
    > TestAction.jsp page (by coding something like:
    >
    > mapping.findForward("testAction");
    >
    > --
    > Tim Slattery
    >
     
    in_dv, Nov 8, 2006
    #5
  6. in_dv

    Tim Slattery Guest

    "in_dv" <> wrote:

    >Thx for the reply. Do I need to keep the same case for forward and
    >struts config?


    No, they're talking about different things. The "path" attribute of
    "action" gives a name that will be matched to the URL sent to the app.
    The "path" attribute of the "forward" tag points to a JSP page.

    --
    Tim Slattery
     
    Tim Slattery, Nov 8, 2006
    #6
  7. in_dv

    in_dv Guest

    So is my information right? I am stll not able to get this work

    Tim Slattery wrote:
    > "in_dv" <> wrote:
    >
    > >Thx for the reply. Do I need to keep the same case for forward and
    > >struts config?

    >
    > No, they're talking about different things. The "path" attribute of
    > "action" gives a name that will be matched to the URL sent to the app.
    > The "path" attribute of the "forward" tag points to a JSP page.
    >
    > --
    > Tim Slattery
    >
     
    in_dv, Nov 9, 2006
    #7
  8. in_dv

    impaler Guest

    On Nov 9, 4:26 pm, "in_dv" <> wrote:
    > So is my information right? I am stll not able to get this work
    >


    Do you have everything set up?

    web.xml should have
    <!--=============================-->
    <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>
    <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>
    <init-param>
    <param-name>application</param-name>
    <param-value>application</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>
    <!--=============================-->

    to load the action servlet and map the *.do (I've noticed that you use
    this) url pattern to the action servlet.

    And also check struts.jar to be in the WEB-INF/lib or in the server's
    common lib folder (with all the dependencies)
     
    impaler, Nov 9, 2006
    #8
  9. in_dv

    in_dv Guest

    Thx for the reply. I have the same entries in my web.xml file and this
    is the output of ls command at WEB-INF/lib directory
    [root@pw-psni-01 lib]# ls
    activation.jar commons-dbcp-1.2.1.jar commons-lang-2.0.jar
    commons-pool.jar pg74.214.jdbc3.jar tax.jar
    commons-beanutils.jar commons-digester.jar commons-logging.jar
    commons-validator.jar servlet.jar
    commons-collections.jar commons-fileupload.jar commons-pool-1.2.jar
    keep.me struts.jar

    ..Kidly let me know what else I should check
    impaler wrote:
    > On Nov 9, 4:26 pm, "in_dv" <> wrote:
    > > So is my information right? I am stll not able to get this work
    > >

    >
    > Do you have everything set up?
    >
    > web.xml should have
    > <!--=============================-->
    > <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>
    > <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>
    > <init-param>
    > <param-name>application</param-name>
    > <param-value>application</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>
    > <!--=============================-->
    >
    > to load the action servlet and map the *.do (I've noticed that you use
    > this) url pattern to the action servlet.
    >
    > And also check struts.jar to be in the WEB-INF/lib or in the server's
    > common lib folder (with all the dependencies)
     
    in_dv, Nov 9, 2006
    #9
  10. in_dv

    in_dv Guest

    Hi all,

    I checked the apache logs and found the error that

    <APP-ROOT>/TestAction.do file does not exist. Its probably
    misunderstanding it as link rather than action.Its trying to look for
    the file TestAction.do rather than finding the action mappings for *.do
    .. What configuration m I missing for this behaviour? I truly appreciate
    your help

    Thanks

    in_dv wrote:
    > Thank you very much for your reply.
    > I am pasting the code for TestAction.java file below
    >
    > /////////////////////////
    >
    > package devika;
    >
    > 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 TestAction extends Action
    > {
    > public ActionForward execute(
    > ActionMapping mapping,
    > ActionForm form,
    > HttpServletRequest request,
    > HttpServletResponse response) throws Exception{
    > return mapping.findForward("testAction");
    > }
    > }
    >
    > //////////////////////////////////
    >
    > Then why m i getting page cannot be diplayed error ?
    > Tim Slattery wrote:
    > > "in_dv" <> wrote:
    > >
    > > >Hello All,
    > > >
    > > >I am a newbie to struts. I am trying to get a simple example working
    > > >which I found on jakarta struts tutorial.
    > > >
    > > >When I click on a link, I expect it to transfer to TestAction.jsp page
    > > >, but I can see it changes to TestAction.do and I get "Page Cannot be
    > > >found" HTTP 404 error.
    > > >
    > > >Followign are the entries in struts-config.xml file
    > > >
    > > ><action
    > > > path="/TestAction"
    > > > type="devika.TestAction">
    > > > <forward name="testAction" path="/TestAction.jsp"/>
    > > > </action>
    > > >
    > > >following is entry in .jsp file
    > > >
    > > ><html:link page="/TestAction.do">Test the Action</html:link>

    > >
    > > That link causes the Struts front end to search the struts-config.xml
    > > file and find the "action" you've reproduced above. That "action"
    > > element tells it to transfer control to "devika.TestAction.class".
    > > Presumably that class will eventually pass control to the
    > > TestAction.jsp page (by coding something like:
    > >
    > > mapping.findForward("testAction");
    > >
    > > --
    > > Tim Slattery
    > >
     
    in_dv, Nov 10, 2006
    #10
  11. in_dv

    impaler Guest

    >
    > .Kidly let me know what else I should check
    >


    Have you tried to launch struts-blank app? Is the app that comes with
    struts and you can use it to start building your struts app atop.
    It's a war file under the app folder of struts.zip (the complete
    download) and just copy it into tomcat's webapps folder and it should
    install and run.

    Compare all your configuration files (struts-config.xml especially) and
    check how it links the action to the jsp.

    Basically struts is as follows:

    You register the action servlet in web.xml and map an url pattern to
    the servlet.
    Each request that falls into the pattern is handled by the Action
    servlet. This takes the struts-config file(s) and identifies the
    actions that will handle the request and will return something (a jsp
    for instance) by finding a forward for the action.

    If you can't make struts-blank work, please post from your server logs
    to investigate more (if the action is actually entered and so on)

    Regards
     
    impaler, Nov 10, 2006
    #11
  12. in_dv

    impaler Guest

    On Nov 10, 4:20 pm, "in_dv" <> wrote:
    > Hi all,
    >
    > I checked the apache logs and found the error that
    >
    > <APP-ROOT>/TestAction.do file does not exist. Its probably
    > misunderstanding it as link rather than action.Its trying to look for
    > the file TestAction.do rather than finding the action mappings for *.do
    > . What configuration m I missing for this behaviour? I truly appreciate
    > your help


    It seems that the servlet hasn't been started or the servlet mapping is
    wrong.
    Check the startup logs of tomcat to see if it fails to start the action
    servlet and if all is ok, check if the *.do pattern is set to be
    handled by action servlet. Watch out for cases ('action' and 'Action'
    are not the same).
     
    impaler, Nov 10, 2006
    #12
  13. in_dv

    in_dv Guest

    Hi I checked out the startup logs, but it doesnt show any error .
    Actually I am working with apache and apache is supposed to forward
    this request to tomcat. which is not happening..Do you know how to
    configure apache to forward the requests to tomcat
    devika
    impaler wrote:
    > On Nov 10, 4:20 pm, "in_dv" <> wrote:
    > > Hi all,
    > >
    > > I checked the apache logs and found the error that
    > >
    > > <APP-ROOT>/TestAction.do file does not exist. Its probably
    > > misunderstanding it as link rather than action.Its trying to look for
    > > the file TestAction.do rather than finding the action mappings for *.do
    > > . What configuration m I missing for this behaviour? I truly appreciate
    > > your help

    >
    > It seems that the servlet hasn't been started or the servlet mapping is
    > wrong.
    > Check the startup logs of tomcat to see if it fails to start the action
    > servlet and if all is ok, check if the *.do pattern is set to be
    > handled by action servlet. Watch out for cases ('action' and 'Action'
    > are not the same).
     
    in_dv, Nov 10, 2006
    #13
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Katie Wright
    Replies:
    8
    Views:
    4,252
    Andrea Desole
    Jan 7, 2005
  2. Jason Us
    Replies:
    0
    Views:
    991
    Jason Us
    Oct 4, 2003
  3. jc1771
    Replies:
    0
    Views:
    407
    jc1771
    Dec 28, 2003
  4. sin
    Replies:
    3
    Views:
    725
    Sudsy
    Feb 22, 2004
  5. Pratap Das
    Replies:
    2
    Views:
    2,035
    Pratap Das
    Apr 5, 2004
Loading...

Share This Page