Results 1 to 4 of 4
- 06-02-2010, 03:06 PM #1
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
- 06-03-2010, 01:44 AM #2
do you mean to have .class files located outside of the webroot, or content files ?
.class files are tricky, because you would need to have the folder (or the jar file) added to the class path, such as by customizing or configuring the class loader of the container, which is difficult to do outside of their standard shared libraries folders.
if you meant to have content like text files fetched from a location outside of the webroot displayed inside a JSP page, then a component that uses standard File IO to read the contents from these files, such as with FileInputStreams and then have it written to the servlet output stream should likely be possible. In this case I would suggest creating some kind of tag library so the logic to do the file reading would be encapsulated nicely in a custom JSP tag. Note as well, you would want to make precautions to sandbox the requests for files such that the JSP tag is only capable of requesting files within some sandboxed path, so as to prevent accidental or malicious JSP authors from reading the contents of privileged system files, such as /etc/passwd
- 06-03-2010, 05:54 AM #3
Member
- Join Date
- May 2010
- Posts
- 3
- Rep Power
- 0
I wanted to load the header/footer jsp pages from outside webroot files?
thanks for your immediate responce, I want to load the header.jsp and footer.jsp files from outside webroot and load them into my actual jsp page. It will be great help if you can give more details or provide the code.
Thanks once again.
- 06-03-2010, 12:06 PM #4
oh, I was thinking for static content files, like text, pdf, images outside the container. For JSP files outside of the container, I'm not sure that is readily possible to do, as JSP pages are compiled into .class files by the JSP compiler Servlet, which I think needs to work with files within a web application context. I think we would need to get into the sources for the JSP compiler, perhaps have a look at Jasper2 from the Tomcat project, and customize it to have its search for JSP files path include the folders outside of the webapplication root. Where a custom JSP servlet is enabled by defining your JSP compiler servlet in your web.xml to override the one in the container default web.xml.
For static content reading, I don't have any specific code, but something like
should work.Java Code:String path = "path to the file" FileInputStream fin = new FileInputStream(path); OutputStream out = response.getOutputStream(); int bytesRead = 0; byte[] buffer = new byte[1024]; while ( (bytesRead = in.read(buffer, 0, bufferSize)) != -1 ) { out.write(buffer, 0, bytesRead); }
Similar Threads
-
Launch Java application with root privileges from gnome desktop shortcut.
By IYIaster in forum New To JavaReplies: 1Last Post: 05-17-2010, 09:03 PM -
Invoke an awt event from outside the swing application
By jasmbhat in forum AWT / SwingReplies: 1Last Post: 09-17-2009, 08:19 AM -
Accessing local file from server side using Java Application
By ersachinjain in forum JDBCReplies: 9Last Post: 09-01-2009, 07:17 PM -
Modify context root in application.xml
By Saurabh321 in forum New To JavaReplies: 1Last Post: 04-17-2009, 11:12 AM -
Running .java-files won't work/compile does!(Code inside)
By wyldstyle in forum New To JavaReplies: 6Last Post: 02-06-2009, 08:05 PM


LinkBack URL
About LinkBacks

Bookmarks