aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Can a request be forwarded to a resource in different web application and the same web container? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Can a request be forwarded to a resource in different web application and the same web container?" Watch "Can a request be forwarded to a resource in different web application and the same web container?" New topic
Author

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

Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
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 Tiwari
| Pursuing Bachelor of Engineering | OSUM Club Leader | SCJP 6 | SCWCD 5 |...
Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
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?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

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


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9304
    
  17

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...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Parth Twari
Ranch Hand

Joined: Jan 20, 2010
Posts: 163
@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

Joined: Aug 03, 2008
Posts: 9304
    
  17

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...
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1695
    
  25

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

Joined: Jan 20, 2010
Posts: 163
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
Bartender

Joined: Apr 07, 2010
Posts: 1695
    
  25

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
Aj Deschanel
Ranch Hand

Joined: Oct 20, 2009
Posts: 40
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


  • SCJP 1.6, SCWCD 1.5
    Parth Twari
    Ranch Hand

    Joined: Jan 20, 2010
    Posts: 163
    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

    Joined: Aug 03, 2008
    Posts: 9304
        
      17

    The exam is not specific to Tomcat, so if the specs say it works, then it works...
    Simran Dass
    Ranch Hand

    Joined: Jan 09, 2010
    Posts: 183

    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

    Joined: Jan 09, 2010
    Posts: 183

    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

    Joined: Jan 20, 2010
    Posts: 163
    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
    Bartender

    Joined: Apr 07, 2010
    Posts: 1695
        
      25

    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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Can a request be forwarded to a resource in different web application and the same web container?