codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Problem Related to file uploading using JSP  Archive Import (Vik) at 23:47 on Friday, May 09, 2003
 

Hi
I am trying to use file uploading JSP but when I run the application I get the following message :
TTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 33 in the jsp file: /upload.jsp

Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:14: expected
[javac] public String getBoundary(HttpServletRequest request,Propertiesprop)
[javac] ^
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:44: `)` expected
[javac] private static java.util.Vector _jspx_includes;
[javac] ^
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:99: not a statement
[javac] line for HOTJAVABROWSER 3.0
[javac] ^



An error occurred at line: 33 in the jsp file: /upload.jsp

Generated servlet error:
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:99: `;` expected
[javac] line for HOTJAVABROWSER 3.0
[javac] ^



An error occurred at line: 33 in the jsp file: /upload.jsp

Generated servlet error:
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:14: cannot resolve symbol
[javac] symbol : class Propertiesprop
[javac] location: class org.apache.jsp.upload_jsp
[javac] public String getBoundary(HttpServletRequest request,Propertiesprop)
[javac] ^
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:14: missing method body, or declare abstract
[javac] public String getBoundary(HttpServletRequest request,Propertiesprop)
[javac] ^
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:47: cannot resolve symbol
[javac] symbol : variable _jspx_includes
[javac] location: class org.apache.jsp.upload_jsp
[javac] return _jspx_includes;
[javac] ^
[javac] /usr/local/jakarta-tomcat-4.1.24/work/Standalone/localhost/~stu012/upload_jsp.java:153: cannot resolve symbol
[javac] symbol : method getFileName (java.lang.String)
[javac] location: class org.apache.jsp.upload_jsp
[javac] String filename = getFileName(secondline);
[javac] ^
[javac] 8 errors









This is my JSP code:

<%@ page errorPage="/forum/error.html" %>
<jsp:useBean id="prop" scope="page" class="java.util.Properties" />
<%@ page import="java.io.*,java.util.*,javax.servlet.*" %>
<%!
public String getBoundary(HttpServletRequest request,Properties prop) throws ServletException,IOException{
String boundary = null;
Enumeration enum = request.getHeaderNames();
while(enum.hasMoreElements()){
String header = (String)enum.nextElement();
String hvalue = request.getHeader(header);
prop.setProperty((header).toLowerCase(),hvalue);
if( "content-type".equalsIgnoreCase(header) ){
int idx = hvalue.lastIndexOf("boundary=");
if( idx != -1 ){
boundary= hvalue.substring( idx+9 , hvalue.length());
}
}
}
return boundary;
}
public String getFileName(String secondline){
int len = secondline.length();
int idx = secondline.lastIndexOf("filename=");
if( idx == -1 ) return null;
String filename = secondline.substring( idx+10 , len-1);
filename = filename.replace(`\\`,`/`);
idx = filename.lastIndexOf("/index.html");
idx = idx + 1;
filename = filename.substring( idx );
return filename;
}
%>
<%
String DPATH = "C:\\temp\\file\\";
int ROUGHSIZE=1024;
int MAXSIZE = 10; // Mega Byte
String boundary = getBoundary(request,prop);
if( boundary == null ){
boundary = prop.getProperty("boundary");// This statement line for HOTJAVABROWSER 3.0
}else{
boundary = "--"+boundary;
}
if( boundary == null ){
throw new Exception("BNF");
}
Long contentsize = new Long(prop.getProperty("content-length","0"));
int c;
StringWriter st = new StringWriter();
if( contentsize.longValue() < 1L ){
throw new Exception("ZERO");
}
long l = contentsize.longValue() - ROUGHSIZE;
/*
You can restrict upload file size in the following way
1. after uploaded u cannt find out file size then display error message
2. from contentsize it will give approximate size of file in bytes.
based on this u can restrict uploading.
*/
int KB = 1024;
int MB = 1024 * KB;
int csize = (int)(l / MB);
if( csize > MAXSIZE ){
throw new Exception("EL");
}
ServletInputStream fin = request.getInputStream();
//Getting Start Boundary Line
int cn;
int count=0;
while( (c=fin.read()) != -1 ){
if( c == `\r`) break;
st.write(c);
count++;
}
c=fin.read();//read new line
String tboundary = st.getBuffer().toString();
tboundary=tboundary.trim();
if( ! tboundary.equalsIgnoreCase( boundary) ){
throw new Exception("BBNF");
}
st.close();
st = null;
st = new StringWriter();
//Getting File Information
while( (c=fin.read()) != -1 ){
if( c == `\r` ) break;
st.write(c);
}
c=fin.read();//read new line
String secondline = st.getBuffer().toString();
String filename = getFileName(secondline);
st.close();
st = null;
st = new StringWriter();
//Read Content Type of File
while( (c=fin.read()) != -1 ){
if( c == `\r` ) break;
st.write( c );
}
c=fin.read();//read new line
//out.println( st.getBuffer().toString() );
//Read \r and \n character
fin.read();
fin.read();
File newfile = null;
FileOutputStream fout =null;
try{
if( filename == null ) throw new FileNotFoundException("File Name not found");
newfile = new File(DPATH+filename);
fout = new FileOutputStream( newfile );
}catch(FileNotFoundException fnexp){
fin.close();
throw new Exception("FNF");
}

byte b[] = null;
while( l > 1024L ){
b = new byte[1024];
fin.read(b,0,1024);
fout.write(b);
b=null;
l -= 1024L;
}
if( l > 0 ){
b = new byte[(int)l];
fin.read(b,0,(int)l);
fout.write(b);
}


ByteArrayOutputStream baos = new ByteArrayOutputStream();
while( (c = fin.read()) != -1 ){
baos.write(c);
}
String laststring = baos.toString();
int idx = laststring.indexOf(boundary);
b = baos.toByteArray();
if( idx > 2 ){
fout.write(b,0,idx-2);
}else
{
fout.close();
newfile.delete();
throw new Exception("EBNF");
}
fout.flush();
fout.close();
fin.close();
%>
<html>
<body>
<TABLE>
<TR>
<TD>FileName</TD><TD><%=newfile.getName()%></TD>
</TR>
<TR>
<TD>FileSize</TD><TD><%=newfile.length()%></TD>
</TR>
</TABLE>
</body>
</html>

and the corresponding HTML code is :
<html>
<head>
</head>
<body>
<form name="Test" method="post" action="/forum/upload.html" enctype="multipart/form-data">
<table width="75%" border="0" cellspacing="1" cellpadding="0" align="center" bgcolor="#8B88AA">
<tr>
<td>
<blockquote>
<p>To attach a file,
type the path of the file or click on the "Browse" button
to locate it in your computer.</p>
</blockquote>
</td>
</tr>
<tr>
<td>
<div align="center"><font size="2">Attachment :</font>
<input type="File" name="picture" >
</div>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td height="17">
<blockquote>
<p>Click on the "Upload
File" button, after selecting the file.</p>
</blockquote>
</td>
</tr>
<tr>
<td height="24">
<div align="center">
<input type="Submit" value="Upload File" name="Submit" >
</div>
</td>
</tr>
</table>
</form>
</html>

Do you ppl have some idea how to reslove this???

  Re: Problem Related to file uploading using JSP  Archive Import (gyopaarka) at 08:25 on Tuesday, July 08, 2003
 

The error messages reflects that there are just compiler syntax errors:
public String getBoundary(HttpServletRequest request,Properties prop)
In this line the compiler doesn t see the SPACE between Properties and prop...
I don`t understand this, because the code you ve attached is good (there is a SPACE).
So?!








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  do static member are inherited
•  Re: Help with Using DataReader with StoredProcedure
•  Perl Script Output (w3c validator)
•  Re: HashMap question
•  focus management?
•  Looping Issue...Please help!
•  regarding hibernate
•  working with plugins
•  Checkbox Validation help.


Recent Articles
What is a pointer in C?
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net


© Copyright codetoad.com 2001-2006