• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

basic question based on request & response ...

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 VI Editor Redhat
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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
     
    The overall mission is to change the world. When you've done that, then you can read this tiny ad:
    Clean our rivers and oceans from home
    https://www.kickstarter.com/projects/paulwheaton/willow-feeders
    reply
      Bookmark Topic Watch Topic
    • New Topic