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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Reply 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
Rancher

Joined: Apr 07, 2010
Posts: 1040

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
Rancher

Joined: Apr 07, 2010
Posts: 1040

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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Accessing one web application from another.
 
Similar Threads
Tomcat 4 : How to deploy and run JSP and Servlets
JDBC and Tomcat
unable to view index.html pahe in webapps folder
Basic JSP problem
multiple directorys seem to stop blazeds to stop working on tomcat 5.5