Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Struts newbie question

Thread view: 
in_dv - 08 Nov 2006 17:08 GMT
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
Tim Slattery - 08 Nov 2006 17:37 GMT
>Hello All,
>
[quoted text clipped - 16 lines]
>
><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
Slattery_T@bls.gov
in_dv - 08 Nov 2006 18:25 GMT
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 ?

> >Hello All,
> >
[quoted text clipped - 28 lines]
> Tim Slattery
> Slattery_T@bls.gov
in_dv - 10 Nov 2006 16:20 GMT
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

> Thank you very much for your reply.
> I am pasting the code for TestAction.java file below
[quoted text clipped - 58 lines]
> > Tim Slattery
> > Slattery_T@bls.gov
impaler - 10 Nov 2006 17:10 GMT
> Hi all,
>
[quoted text clipped - 5 lines]
> . 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 - 10 Nov 2006 19:41 GMT
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
> > Hi all,
> >
[quoted text clipped - 12 lines]
> handled by action servlet. Watch out for cases ('action' and 'Action'
> are not the same).
richardsosborn@gmail.com - 08 Nov 2006 17:44 GMT
Your case is different in the forward and Struts Config.

> Hello All,
>
[quoted text clipped - 20 lines]
>
> D
in_dv - 08 Nov 2006 18:24 GMT
Thx for the reply. Do I need to keep the same case for forward and
struts config?

> Your case is different in the forward and Struts Config.
>
[quoted text clipped - 22 lines]
> >
> > D
Tim Slattery - 08 Nov 2006 21:17 GMT
>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
Slattery_T@bls.gov
in_dv - 09 Nov 2006 16:26 GMT
So is my information right? I am stll not able to get this work

> >Thx for the reply. Do I need to keep the same case for forward and
> >struts config?
[quoted text clipped - 6 lines]
> Tim Slattery
> Slattery_T@bls.gov
impaler - 09 Nov 2006 16:59 GMT
> 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 - 09 Nov 2006 19:38 GMT
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
> > So is my information right? I am stll not able to get this work
>
[quoted text clipped - 37 lines]
> 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 - 10 Nov 2006 16:35 GMT
> .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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.