Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > using a JSP to do a file read

Reply
Thread Tools

using a JSP to do a file read

 
 
anikkar@gmail.com
Guest
Posts: n/a
 
      11-02-2005
Hi,

I am in the learning stages of using JSPs, and i am tryin to write a
utility which will unzip a file on a server (this is because i have had
to much trouble uploading a folder with the unzip'd contents...i.e.
100s of files).

I quickly found that i don't have read permissions:

exception

org.apache.jasper.JasperException: access denied
(java.io.FilePermission / read)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
sun.reflect.GeneratedMethodAccessor152.invoke(Unkn own Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(Se curityUtil.java:239)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject .java:517)
org.apache.catalina.security.SecurityUtil.execute( SecurityUtil.java:266)
org.apache.catalina.security.SecurityUtil.doAsPriv ilege(SecurityUtil.java:157)

root cause

java.security.AccessControlException: access denied
(java.io.FilePermission / read)
java.security.AccessControlContext.checkPermission (AccessControlContext.java:264)
java.security.AccessController.checkPermission(Acc essController.java:427)
java.lang.SecurityManager.checkPermission(Security Manager.java:532)


But this doesn't seem to make sense to me, as you would imagine that I
would have read permissions on the server.

Here is the code:

<%@ page import="java.util.Enumeration"%>
<%@ page import="java.io.File"%>
<html>
<body>
<form action="unzip.jsp" method=post>
<SELECT NAME="File" SIZE=4>
<% File dir = new File("/");
for(File tempFile : dir.listFiles()) { %>
<OPTION><%=tempFile%></OPTION>
<% } %>

</SELECT>
<INPUT TYPE=SUBMIT VALUE=Press>
</form>
<B>Form Content</B><BR>
<TABLE>
<% Enumeration parameters = request.getParameterNames();
while(parameters.hasMoreElements()){
String parameterName = (String)parameters.nextElement();
String parameterValue = request.getParameter(parameterName);
%>
<TR>
<TD><%=parameterName%></TD>
<TD><%=parameterValue%></TD>
</TR>
<% } %>
</body>
</html>

 
Reply With Quote
 
 
 
 
Shorty
Guest
Posts: n/a
 
      11-02-2005
Does the user running the application server have the right to read on
the root ("/") directory on the server ? (I mean based on unix access
rights)

 
Reply With Quote
 
 
 
 
anikkar@gmail.com
Guest
Posts: n/a
 
      11-02-2005
Not quite sure what you mean by the user running the application? I ran
another JSP which read the system properties, and it listed that the
user.dir = /, user.home = /root, and user.name = root.

so i tried using File("/root"), but that didn't work either

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-03-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:


> <% File dir = new File("/");


When you don't know what is happening, print it out..

out.print( dir + " " + dir.exists() );

...then try, either..
<http://java.sun.com/j2ee/sdk_1.2.1/techdocs/api/javax/servlet/ServletContext.html#getRealPath(java.lang.String)>
or..
<http://java.sun.com/j2ee/sdk_1.2.1/techdocs/api/javax/servlet/ServletContext.html#getResource(java.lang.String)>

HTH
 
Reply With Quote
 
anikkar@gmail.com
Guest
Posts: n/a
 
      11-03-2005
Hi Andrew,

thanks for your suggestion...using the servlet context to get my path
was the trick...my provider never gaver me my path, so i was
accidentally trying to access the root.

thanks again!

 
Reply With Quote
 
Andrew Thompson
Guest
Posts: n/a
 
      11-03-2005
(E-Mail Removed) wrote:

> thanks for your suggestion...using the servlet context to get my path
> was the trick...my provider never gaver me my path, so i was
> accidentally trying to access the root.


Cool. I figured you would work it out from the links.

Glad you sorted it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
File.read(fname) vs. File.read(fname,File.size(fname)) Alex Dowad Ruby 4 05-01-2010 08:20 AM
<jsp:useBean File Read Write, File Locations and GoDaddy.com LB Java 0 05-27-2008 01:44 AM
Declaring a variable in one JSP file and accessing it in another JSP file anubhakhurana@gmail.com Java 8 10-11-2006 01:15 AM
[JSP] difference between jsp:forward and jsp:include alexjaquet@gmail.com Java 0 06-02-2006 01:21 PM
[JSP] Strings Constants from JSP using Struts tags Matthias Nietz Java 1 11-12-2003 04:32 PM



Advertisments