aspose file tools*
The moose likes JSP and the fly likes doubt in scriptless JSPs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "doubt in scriptless JSPs" Watch "doubt in scriptless JSPs" New topic
Author

doubt in scriptless JSPs

nidhivel raja
Ranch Hand

Joined: Jun 26, 2008
Posts: 36
Hi all,
I read the following concept from the Head First Servlets and JSP book (second edition)(page 420)
The following is an abstract Bean class person

The following is the subclass of Person



The following is the standard action in a jsp file






The following is the servlet code





Now coming to my problem
The book says The servlet code FAILS at request time,The person attribute is stored at request scope,so the <jsp:useBean>tag won't work since it specifies only a type.The Container KNOWS that if you have only a type specified there must be an existing attribute of that name and scope


My doubt is

1.How the servlet code is linked to the jsp page I mean there is no form action tag given here?[/B

2.[B]What is request time ?


3.How is the person attribute's scope related to the type of the useBean tag


Please do help me Thank you in advance.....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Please avid the overuse of bold.

Originally posted by nidhivel raja:
1.How the servlet code is linked to the jsp page I mean there is no form action tag given here?
The servlet code is not linked to the JSP. That's the beauty of loose coupling. The servlet has created a scoped variable named person (via setAttribute()) that is available to the JSP.

2.What is request time ?
When the request is being executed.

3.How is the person attribute's scope related to the type of the useBean tag
The useBean tag will look for the scoped variable in a specified scope or all scopes.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
nidhivel raja
Ranch Hand

Joined: Jun 26, 2008
Posts: 36
Thank you Mr.Bear Bibeault ,for your timely help.So the useBean can only use the variable if it is in the request scope right?

My question is how this problem can be solved i mean when exactly a request scope is created .......Is it created when a servlet services another jsp's request or when the servlet is compiled?


Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
It is fairly obvious if you invoke the jsp directly, you will get a runtime error, because the bean "person" is not in scope, and it can't create one on the fly.

The servlet's responsibility is to set up the "person" bean, so that the jsp can use it.

What links the two? What tells it to run the servlet first and then the JSP? And which JSP?
That is normally the job of a "controller"

Normally code something like this:


If this was in your servlet it would tell it to forward to the jsp "fooTest.jsp" once it was finished processing.


The HttpRequest is triggered by exactly that. A client (normally a browser) making a request of the server. The server receives the connection from the browser, creates an HttpServletRequest object for you to use, and then invokes the servlet/jsp which was referenced, passing in the request object as a parameter. This is all done by the servlet container.

Request scope is the scope of one request-response cycle. Ie the server receives a request from the browser, and sends back a response.
Session scope (by contrast) can go over multiple requests from the same user.
You can specify any of the 4 attribute scopes for a bean to "live" in and it will look for it there.

Cheers,
evnafets
nidhivel raja
Ranch Hand

Joined: Jun 26, 2008
Posts: 36
Thank you Mr.Stefan Evans I have solved that problem........
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt in scriptless JSPs