Win a copy of Java 9 Modularity: Patterns and Practices for Developing Maintainable Applications this week in the Java 9 forum!
    Bookmark Topic Watch Topic
  • New Topic

File Uploading using Jsp and Servlets.  RSS feed

 
Pavithra Praveen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Report post to moderator
i am to execute a small example to upload a file. It is a application developed using Jsp and servlets.

Folder Structure:

Upload(project folder placed in webapps folder)
Main.html
Jsp1.jsp
\WEB-INF
\classes
FileUpload.java

Main.html
---------

HTML
HEAD
TITLE File Upload TITLE
HEAD
BODY
FORM ACTION=Jsp1.jsp ENCTYPE="MULTIPART/FORM-DATA" METHOD=POST
Author: INPUT TYPE=TEXT Name=Author
BR
Company: INPUT TYPE=TEXT Name=Company
BR
Select file to upload: INPUT TYPE=FILE Name=Filename
BR
INPUT TYPE=SUBMIT VALUE="Upload"
FORM
BODY
HTML

Jsp1.jsp
--------

jsp:useBean id="TheBean" scope="page" class="SimpleBean"
%
TheBean.doUpload(request);
%

FileUpload.java
---------------

import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletInputStream;

public class FileUploadBean {

public void doUpload(HttpServletRequest request) throws
IOException {
PrintWriter pw = new PrintWriter(
new BufferedWriter(new FileWriter("Demo.out")));
ServletInputStream in = request.getInputStream();

int i = in.read();
while (i != -1) {
pw.print((char) i);
i = in.read();
}
pw.close();
}
}

I am trying to execute this application, but after i click on Upload Button it is showing error as follows:

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

An error occurred at line: 1 in the jsp file: /Jsp1.jsp
Generated servlet error:
D:\jakarta-tomcat-5.0.28\work\Catalina\localhost\upload\org\apache\jsp\Jsp1_jsp.java:42: cannot resolve symbol
symbol : class SimpleBean
location: class org.apache.jsp.Jsp1_jsp
SimpleBean TheBean = null;
^


An error occurred at line: 1 in the jsp file: /Jsp1.jsp
Generated servlet error:
D:\jakarta-tomcat-5.0.28\work\Catalina\localhost\upload\org\apache\jsp\Jsp1_jsp.java:44: cannot resolve symbol
symbol : class SimpleBean
location: class org.apache.jsp.Jsp1_jsp
TheBean = (SimpleBean) _jspx_page_context.getAttribute("TheBean", PageContext.PAGE_SCOPE); ^


An error occurred at line: 1 in the jsp file: /Jsp1.jsp
Generated servlet error:
D:\jakarta-tomcat-5.0.28\work\Catalina\localhost\upload\org\apache\jsp\Jsp1_jsp.java:46: cannot resolve symbol
symbol : class SimpleBean
location: class org.apache.jsp.Jsp1_jsp
TheBean = new SimpleBean();
^
3 errors

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not post the same question multiple times: CarefullyChooseOneForum

Let's continue the discussion in this duplicate thread, where you have answers already.
[ August 31, 2007: Message edited by: Ulf Dittmer ]
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!