• Post Reply Bookmark Topic Watch Topic
  • New Topic

basic question based on request & response ...  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1] what this method do :

response.createURI();

---------------------------

2] what is the concept of setting an attribute & getting it into another jsp or servlet . I mean how another jsp know that this request object is same one for that we have set attribute . I mean , are we passing that request object to another jsp or servlet , can you please post some code , how to do that ....

---------------------------

Thanks a lot .
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1] what this method do :
response.createURI();

Never heard of it.
Neither has the j2ee API



2] what is the concept of setting an attribute & getting it into another jsp or servlet . I mean how another jsp know that this request object is same one for that we have set attribute . I mean , are we passing that request object to another jsp or servlet , can you please post some code , how to do that ....


ServletContext is available to your whole app.
Session is available to all requests made in a given user's session.
Request is available for the life of one request cycle.

These are very fundamental issues to Servlet/JSP programming and are covered in the early chapters of any Servlet or JSP book.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext is available to your whole app.
Session is available to all requests made in a given user's session.
Request is available for the life of one request cycle.

All three points are clear , but my question is different ... please have a look ...

Thanks .
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If those 3 points are clear, your question should be answered.

Maybe you can re-phrase your question.
I might not understand what you are asking.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK , I am trying with example :



I am sure there are lots of problem with code but please ignore them . My concern is , how can we get a list into a jsp that we made in any other jsp ...

is this clear ...

Thanks .
 
Hemanth Pallavajula
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

In regard to existence of Request scope objects, I have a doubt.

If I have a JSP and within that there is a Frame and a seperate JSP in that frame. Now I am passing an object to the main JSP by putting it in request scope. If i try to retrieve the same object from the request scope of inner frame's jsp, then I get null. This means that the object is not available for the inner JSP. But here, I am not losing the session, as I am not going to the server. I am only setting the SRC attribute of Frame to a particular jsp.

Please help regarding this.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With regard to Rathi's question:

JSPs and servlets are functionally the same. Pretty much anything I can do in a servlet, I can do in a JSP. This means that either a Servlet or a JSP can place an object in the Session context or the Servlet context and have other Servlets or JSPs retrieve it. However, the rules for request scope are a little different. If I write a servlet that puts something in request scope, only a servlet or JSP that I forward to using RequestDispatcher.forward() can use that object, because only then will that servlet or jsp share the same request context with my servlet. Since the rules for RequestDispatcher.forward() are that you can't output to the response object before forwarding, it doesn't make much sense for one JSP to forward to another.

With regard to Hemanth's question:

The "src" attribute of a frame essentially calls the URL you specify. This initiates a new request, so the jsp specified in the URL does not share the same request context as the jsp containing the frame. If you want to instantiate an object before displaying the jsp, specify a servlet in your src attribute, and have your servlet instantiate the object and forward to the jsp.

The sequence of events is as follows:
  • Servlet instantiates object and forwards to frame jsp
  • frame jsp shares same request context with servlet and can use the object
  • frame jsp outputs html which is sent back to the browser
  • html from frame jsp is displayed on the browser
  • in this html, there is a frame tag with a src attribute that causes a new html request to be sent to the server.
  • This starts the process all over again, and causes a new request context to be created.
  • the URL is processed by the server and the results displayed inside the frame created by the previous request.


  • [ March 09, 2005: Message edited by: Merrill Higginson ]
     
    Ben Souther
    Sheriff
    Posts: 13411
    Firefox Browser Redhat VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    rathi ji,

    Merrill's answer is correct.
    If you want a working example, SimpleMVC on http://simple.souther.us does just this. From a servlet, it creates a bean, binds it to request scope, and then forwards to a JSP which reads values from the bean.

    Good-Luck
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!