aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Accessing one web application from another. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Accessing one web application from another." Watch "Accessing one web application from another." New topic
Author

Accessing one web application from another.

Dmitri Cherkas
Ranch Hand

Joined: Mar 22, 2010
Posts: 40
Hello,

if i have the following two very simple web applications running on the same server :

1) the FIRST is : \tomcat\webapps\FIRST\WEB-INF\classes\test\FirstForAccessTheSecond.class

2) the SECOND is :
\tomcat\webapps\SECOND\index.html
\tomcat\webapps\SECOND\folder1\folder1.jsp

the questions are :
Can the "FirstForAccessTheSecond.class" of the FIRST application access the "index.html" file of the SECOND application to modify it ?
Can the "FirstForAccessTheSecond.class" of the FIRST application delete the "folder1" of the SECOND application ?

If no - why ? Can you indicate where J2EE specification specify it ?

Thank you in advance,
Dmitri.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1718
    
  25

Hi Dmitri,

A RequestDispatcher from the ServletContext of web-application A can get to the ServletContext of web-application B as long as A and B are located in the same JVM (web-container) and the web-container allows it. By default, for instance, Tomcat doesn't allow this (security risk). You can change this setting in the server.xml or config.xml: <Context crossContext="true">

In web-application A you can read a file from web-application B by calling getResourceAsStream() on the ServletContext of B:

You can't modify or delete this file though. (because there is nowhere in the specs, that specifies that you can do that .....)

Regards,
Frits
Dmitri Cherkas
Ranch Hand

Joined: Mar 22, 2010
Posts: 40
Hi Frits,

thank you very much for the competent response with the clear example !

Only one observation...

You can't modify or delete this file though. (because there is nowhere in the specs, that specifies that you can do that .....)


the contrary of your note, though, is true : if specs doesn't specify explicitly that you can't do something you CAN do that thing. Therefore if the specs doesn't say that you cann't delete the file in another webapplication, in theory, you CAN do it. I think that, in this case, the implementation of the webcontainer (Tomcat) can allow or disallow it.

Have a nice weekend !
Dmitri.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1718
    
  25

Hi Dmitri,

the contrary of your note, though, is true : if specs doesn't specify explicitly that you can't do something you CAN do that thing.

It really depends, but we are here on the certification forum. During the exam you will only be questioned of what is specified.
Furthermore if something is not specified and it is, for instance, possible in Tomcat your code for sure won't be portable to another web-container. Therefore not recommendable.

Apart from that: if you look closely at the API you will find a context.getResourceAsStream(String path), but nowhere a setResourceAsStream(String path) .

Regards and have a nice weekend too !

Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing one web application from another.