This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes updating server.xml from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "updating server.xml from servlet" Watch "updating server.xml from servlet" New topic
Author

updating server.xml from servlet

James Byars
Ranch Hand

Joined: Apr 15, 2009
Posts: 42
hi,

how can I update servlet.xml from inside a servlet. I ask this question because we can only access stuff under webapps, server.xml is outside webapps.

thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why on earth would you want to?
James Byars
Ranch Hand

Joined: Apr 15, 2009
Posts: 42
David Newton wrote:Why on earth would you want to?


I want to have a user intercfae on my web page which only certain people with an admin role can use to change the port number and restart tomcat.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Um... oh. So the next person that tried to use the interface couldn't even connect?

IMO this is a really bad idea. In any case, server side code can access any file anywhere, if the user running the container has access to the directory/file. I suppose you could look at the Tomcat Ant task to see about how to restart, unless it's set up to restart automagically on a file change. And hope that the user remembers the port they typed in or didn't make a typo.
James Byars
Ranch Hand

Joined: Apr 15, 2009
Posts: 42
David Newton wrote:Um... oh. So the next person that tried to use the interface couldn't even connect?

IMO this is a really bad idea. In any case, server side code can access any file anywhere, if the user running the container has access to the directory/file. I suppose you could look at the Tomcat Ant task to see about how to restart, unless it's set up to restart automagically on a file change. And hope that the user remembers the port they typed in or didn't make a typo.


thanks.

I am trying to link to a file outside my webapps, using rhe page below which I googled, but am confused as to what I should be using for [context-path].xml - my web page address is http://localhost:7777/test/test1

thanks





By default, Tomcat prevents all webapps from accessing files or directories outside the container. Even if you define a symlink inside the container that can be properly navigated outside using the file system, Tomcat's resource loader will normally refuse to follow a symlink.
If you already have a lot of files and directories that you manage elsewhere in the file system, e.g. a photo collection, then you will need to circumvent the security feature in the best way possible.

1. Create a symbolic (soft) link within the jspWiki container to your external directory, e.g.

ln -s /real/path/to/my/photos/ /[tomcat-home]/[webapps-dir]/[wiki-path]/files/photos

1. Verify the new symlink works properly, e.g. these two commands should produce the same results:

ls -l /real/path/to/my/photos/
ls -l /[tomcat-home]/[webapps-dir]/[wiki-path]/files/photos/

1. Permit your webapp to follow symlinks by pre-defining a Context entry in an xml file available to Tomcat when it starts, but outside the webapp container. The path and filename should be...

$CATALINA_HOME/conf/[engine-name]/[host-name]/[context-path].xml

You can discover the correct values for your [engine-name] and [host-name] from your server.xml file, by referring to the Engine and Host xml elements. The [context-path] is the url path to your webapp, e.g. "jspWiki".
The [context-path].xml file can be as simple as this...

<Context allowLinking="true">

1. Finally, restart Tomcat to establish the new environment for your webapp.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Webapps disallow file access from the *client* side. The *server* side, i.e. the webapp code, can access any file the user running the Tomcat instance has access to (I think I already said that).
James Byars
Ranch Hand

Joined: Apr 15, 2009
Posts: 42
David Newton wrote:Webapps disallow file access from the *client* side. The *server* side, i.e. the webapp code, can access any file the user running the Tomcat instance has access to (I think I already said that).


Sorry, you probably did but I am just confused.

At the moment I am displaying an image from $CATALINA_BASE/webapps/test/testImage.jpg

I want the images to instead be in /fs1/images

Are you saying I can use my servlet to a href to an image in /fs1/images?

thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

More or less. Search for "image servlet".
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 643
I would just like to clarify something. When you say "use my Servlet to a href to an image...", your language can be misleading as it is not clear at all.

To do what you want, you need to create an <img> tag on your response page. The 'src' attribute of this tag will be a URL to an 'Image Servlet' contained by your web application. You will pass a parameter to this servlet so it can tell which image you want to serve. The Image Servlet then can access the file from the file system (even outside the web application directories) to read the file and send it to the client.

A couple points about this: Your servlet container is running as a user on your system. That "user" needs to have read access to the file. Ask questions if you don't understand what this means.

Second: Your Image Servlet must take great care to make sure it will only serve files you want to serve. If it will just serve anything asked of it, a hacker could ask your servlet to serve sensitive operating system files and use that information to hack your machine. Ask questions if you don't understand what this means.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: updating server.xml from servlet
 
Similar Threads
Can I deploy a Servlet differently?
Servlet mapping
Tomcat 5.5 manual deployment
servlet mapping - sybex book
tomcat