This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts handle first request. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts handle first request." Watch "Struts handle first request." New topic
Author

Struts handle first request.

Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Hi

I have simple question about how struts handle jsp page for the first time.

Lets say i have jsp page called index.jsp which has a form with some elements.

I know whenever this form is submitted ActionServlet receives the request and then delegates it to the RequestProcessor which call series of method to get the action path and create mapping,form and action etc.

But how the index.jsp itself is handled for the first time.

I.e lets say if i have entered the url http://localhost:80/index.jsp for the first time.

Then RequestProcessor class gets the path,but,the path is not an action it is just jsp page to display(no mapping found in struts config.xml) so probably most of the process method return null right?

SO how struts handle this request and display the jsp page.

Your help is appreciated.


SCJP 6,SCWCD 5,SCBCD 5

Failure is not an option.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Struts doesn't handle requests for JSP pages by default--the container does. Typically, Struts 1 handles requests mapped to the "*.action" pattern, which isn't "*.jsp".
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
is this true,even if i set the URL patttern for jsp to be handled by ActionServlet in web.xml?

Also what about after execute method returns,lets say it has to forward the request to jsp,so even in this case is it the container that handles the request?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Siva Masilamani wrote:is this true,even if i set the URL patttern for jsp to be handled by ActionServlet in web.xml?

Of course not; if you change it, it'll be whatever you changed it to.

Also what about after execute method returns,lets say it has to forward the request to jsp,so even in this case is it the container that handles the request?

Not sure what you're asking--here you're saying you're accessing a JSP *via* an action, as opposed to accessing the JSP directly.

Ideally, a Struts application will never access a JSP directly.
Siva Masilamani
Ranch Hand

Joined: Sep 19, 2008
Posts: 385
Let me put it clearly

ActionServlet is configured in web.xml in such a way that it has to handle request coming in with either .do or .jsp

here is my action mapping


Let's say,the execute method returns the forward name as success,so the request should be forwarded to the jsp page.

Since i have configured that it should be handled by ActionServlet,how struts handles this request ?
If it calls RequestProcessor method it definitely won't find any Action mapping for the path associated with the request as the path ends with .jsp
?.

So in that case how struts handles the request?is there any condition like if the path is for .jsp it should be handled by container?

Also if index.jsp is my home page and when i type the URL as http:/localhost:80/webapp/index.jsp.

Since i have configured that this request should be handled by ActionServlet,how this request is handled?

Hope i have clearly explained my question.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts handle first request.
 
Similar Threads
PRoblem in displaying ActionForm
Struts Flow of Execution with no form
How do i automatically load a jsp tiles page when by default?
Newbie: Struts 1 -> Passing from one struts action to another
saveToken, isTokenValid, resetToken