• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can a request be forwarded to a resource in different web application and the same web container?

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet A receives a request and forwards it to servlet B in different web application but the same web container .

Is this line true?

can a servlet forward request to a different web app in same web container?
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another Question -

Rewritten URLs is not an efficient method used for state management is case the client submits an HTML form rather than clicking an hyperlink?

True / False

Answer given : True

source of both above: whizlab simulator

whats your take?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure who moved this to the servlets forum, but it's not appropriate. Moved back to the certification forum.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Check the ServletContext class, it has a getContext method to get a ServletContext object of another web app on the same container. You can get a RequestDispatcher on that ServletContext object.

2) I don't necessarily agree with the second answer...
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I'm not sure who moved this to the servlets forum, but it's not appropriate. Moved back to the certification forum.


I did, because there was only the first post at the time I moved it. The first post is a general Servlet question, not an SCWCD question.
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@ankit - the first one i got it absolutely. thanks

the second one - try to understand this question

URL rewritting is used by using the encodeURL and encodeRedirectURL methods. But when you are submitting a form you use action="url string" thats it. you cannot encode your url from here can you?

From what i read in whizlabs is that while FORM submit one has to use Hidden Variable to keep state and while using hyperlinks one has to use URL rewritting.(given cookies are disabled)

Right?
 
Ankit Garg
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Marcus Tiwari wrote:But when you are submitting a form you use action="url string" thats it. you cannot encode your url from here can you?


You can encode (rewrite) the URL. You can use c:url tag.

From what i read in whizlabs is that while FORM submit one has to use Hidden Variable to keep state and while using hyperlinks one has to use URL rewritting.(given cookies are disabled)


Hidden form fields cannot be used to maintain the normal session behavior that we use. The session ID value can either be sent using Cookie (the cookie's name is JSESSIONID) or URL rewriting. When you use a hyperlink, then cookies are not disabled. The browser sends the JSESSIONID cookie to the server when you click on a hyperlink too...
 
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hidden form fields cannot be used to maintain the normal session behavior that we use.


In normal circumstances you would use either URL rewriting or Cookies for session management, but there is another way of maintaining state and that is by using hidden fields. It seems Whizlabs doesn't explain how that works. Let me try to give you an idea how that works:

Where you would normally store an object in the HttpSession object, you now serialize it into a String and send it all the way to the jsp (where you let it be submitted back with the next form submit as an hidden field). In the next action you will get the String object from the request and deserialize into an Object again. The web-container has no idea that those two requests belong to the same session (if Cookies are switched off and URL rewriting is not used) as you are maintaining the state, hence HttpServletRequest.isRequestedSessionIdFromCookie() and HttpServletRequest.isRequestedSessionIdFromURL() are both false.

Regards,
Frits
 
Parth Twari
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can encode (rewrite) the URL. You can use c:url tag.



c:url can only be used in a JSP.
and by the first one you mean encodeURL i think, so is this generated html from servlet correct?

<form action="/myapp/myservlet;jsessionid=314564654654">...</form>

but there is another way of maintaining state


so Frits sets it up that Hidden Fields can be used to maintain state.

But Frits the question is
Rewritten URLs is not an efficient method used for state management is case the client submits an HTML form rather than clicking an hyperlink?

True / False
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3411
320
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcus,

Rewritten URLs is not an efficient method used for state management is case the client submits an HTML form rather than clicking an hyperlink?



I don't know what they mean with efficient, setting up a html form in a jsp with a <c:url> is like this:

and doing the same via a hyperlink is like this:


I don't see any difference in efficiency here

Regards,
Frits
 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ankit Garg wrote:1) Check the ServletContext class, it has a getContext method to get a ServletContext object of another web app on the same container. You can get a RequestDispatcher on that ServletContext object.


By specs this is allowed to return null.
If we talk about tomcat, then you need to set crossContext=true (false by default) in order to get the Context of another app within the same container.
  • servlet 2.5 (SRV.15.2.8 )
  • http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
  •  
    Parth Twari
    Ranch Hand
    Posts: 163
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I don't see any difference in efficiency here



    I think you are right frits.

    By specs this is allowed to return null.



    Well... what I wanted to know is , is it possible or not and it was made clear that it is.However by set crossContext=false it may be disabled.

    thanks
     
    Ankit Garg
    Sheriff
    Posts: 9707
    43
    Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    The exam is not specific to Tomcat, so if the specs say it works, then it works...
     
    Ranch Hand
    Posts: 183
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I am using Tomcat 5.5. In the following code I am trying to get ServletContext for another
    application "appl2" but it is returning null. Current application is "appl1".




    How do I get it working.
     
    Simran Dass
    Ranch Hand
    Posts: 183
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    OOPS ! Did not read the crossContext part carefully in this thread

    getContext() worked after setting crossContext=true in the context.xml file .

    Sorry for asking the question.
     
    Parth Twari
    Ranch Hand
    Posts: 163
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    I don't see any difference in efficiency here

    Regards,
    Frits



    Hi Frits , it seems like i got what the authors of the writers meant when they were saying efficiency while submitting FORM

    Rewritten URLs is not an efficient method used for state management is case the client submits an HTML form rather than clicking an hyperlink?



    Look it is problematic to use Rewritten URLs when using FORM BASED authentication as spec says

    Form based login and URL based session tracking can be problematic to implement.
    Form based login should be used only when sessions are being maintained by
    cookies or by SSL session information.



    So i think on this they made this question.
     
    Frits Walraven
    Creator of Enthuware JWS+ V6
    Posts: 3411
    320
    Android Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hmm, I see, but if they meant that part of the specs they should have talked about FORM based authentication instead of submitting a HTML form.

    I don't think BASIC and FORM based authentication should be used outside a SSL enviroment anyway because of the lack of encryption of the username and password....

    Regards,
    Frits
     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic