Struts newbie question

I

in_dv

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
 
T

Tim Slattery

in_dv said:
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
(e-mail address removed)
 
I

in_dv

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

in_dv

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 ?
 
T

Tim Slattery

in_dv said:
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
(e-mail address removed)
 
I

impaler

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)
 
I

in_dv

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
 
I

in_dv

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
 
I

impaler

.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
 
I

impaler

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).
 
I

in_dv

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top