I am getting the following error..................


HTTP 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: 9 in the generated java file
Only a type can be imported. org.apache.commons.fileupload.servlet.ServletFileUpload resolves to a package

An error occurred at line: 10 in the generated java file
Only a type can be imported. org.apache.commons.fileupload.disk.DiskFileItemFactory resolves to a package

An error occurred at line: 19 in the jsp file: /employee_upload_profile_image.jsp
ServletFileUpload cannot be resolved
16: int count1=0,count2=0,count3=0,count4=0,count5=0;
17: %>
18: <%
19: boolean isMultipart = ServletFileUpload.isMultipartContent(request);
20: if (!isMultipart) {
21: } else {
22: FileItemFactory factory = new DiskFileItemFactory();


An error occurred at line: 22 in the jsp file: /employee_upload_profile_image.jsp
FileItemFactory cannot be resolved to a type
19: boolean isMultipart = ServletFileUpload.isMultipartContent(request);
20: if (!isMultipart) {
21: } else {
22: FileItemFactory factory = new DiskFileItemFactory();
23: ServletFileUpload upload = new ServletFileUpload(factory);
24: List items = null;
25: try {


An error occurred at line: 22 in the jsp file: /employee_upload_profile_image.jsp
DiskFileItemFactory cannot be resolved to a type
19: boolean isMultipart = ServletFileUpload.isMultipartContent(request);
20: if (!isMultipart) {
21: } else {
22: FileItemFactory factory = new DiskFileItemFactory();
23: ServletFileUpload upload = new ServletFileUpload(factory);
24: List items = null;
25: try {


An error occurred at line: 23 in the jsp file: /employee_upload_profile_image.jsp
ServletFileUpload cannot be resolved to a type
20: if (!isMultipart) {
21: } else {
22: FileItemFactory factory = new DiskFileItemFactory();
23: ServletFileUpload upload = new ServletFileUpload(factory);
24: List items = null;
25: try {
26: items = upload.parseRequest(request);


An error occurred at line: 23 in the jsp file: /employee_upload_profile_image.jsp
ServletFileUpload cannot be resolved to a type
20: if (!isMultipart) {
21: } else {
22: FileItemFactory factory = new DiskFileItemFactory();
23: ServletFileUpload upload = new ServletFileUpload(factory);
24: List items = null;
25: try {
26: items = upload.parseRequest(request);


An error occurred at line: 27 in the jsp file: /employee_upload_profile_image.jsp
FileUploadException cannot be resolved to a type
24: List items = null;
25: try {
26: items = upload.parseRequest(request);
27: } catch (FileUploadException e) {
28: e.printStackTrace();
29: }
30: Iterator itr = items.iterator();


An error occurred at line: 33 in the jsp file: /employee_upload_profile_image.jsp
FileItem cannot be resolved to a type
30: Iterator itr = items.iterator();
31: while (itr.hasNext())
32: {
33: FileItem item = (FileItem) itr.next();
34: if (item.isFormField())
35: {
36: String name = item.getFieldName();


An error occurred at line: 33 in the jsp file: /employee_upload_profile_image.jsp
FileItem cannot be resolved to a type
30: Iterator itr = items.iterator();
31: while (itr.hasNext())
32: {
33: FileItem item = (FileItem) itr.next();
34: if (item.isFormField())
35: {
36: String name = item.getFieldName();


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:367)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:342)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.6 logs.

i m getting this error,
plz help me to solve this problem


My Code is as under:

employee_upload_profile_image.html

<html>
 <head><title>Upload page</title></head></p> <p><body>
 <form action="employee_upload_profile_image.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1">
   <center>
   <table border="2">
       <tr>
	       <td align="right"><b>Employee Name:</td>
		   <td ><input type="text" name="emp_name"></td>
	   </tr>
	   <tr>
	       <td align="right"><b>Employee Address:</td>
		   <td ><input type="text" name="address1"></td>
		   
	   </tr>
	   <tr>
	       <td>
		   </td>
		   <td>
		      <input type="text" name="address2">
		   </td>
	   </tr>
	   <tr>
	       <td align="right"><b>Contact Number:</td>
		   <td ><input type="text" name="contact_number"></td>
	   </tr>
       <tr>
	       <td align="right"><b>Employee Email ID:</td>
		   <td ><input type="text" name="email_id"></td>
	   </tr>
	   
       <tr>
	       <td align="right"><b>Employee Image </td>
	       <td>
		       <input name="file" type="file" id="file">
		   <td>
	   </tr>
	   
		 <tr>
		    <td align="center">
               <input type="submit" name="Submit" value="Submit"/>
			   <input type="reset" name="Reset" value="Reset"/>

			</td>
		 </tr>
    </table>
	</center>
 </form>
 </body>
 </html>

employee_upload_profile_image.jsp

<%@ page import="java.util.List" %>
   <%@ page import="java.util.Iterator" %>
   <%@ page import="java.io.File" %>
   <%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
   <%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
   <%@ page import="org.apache.commons.fileupload.*"%>
   <%@ page contentType="text/html;charset=UTF-8" language="java" %>
  
       <center><h1>Your  Profile has been Uploaded</h1></center>
   <%!
     String emp_name="";	 
	 String emp_c_number="";
	 String emp_emailid="";
     String address1="";
	 String address2="";
	 int count1=0,count2=0,count3=0,count4=0,count5=0;
 %>
 <%
 boolean isMultipart = ServletFileUpload.isMultipartContent(request);
 if (!isMultipart) {
 } else {
   FileItemFactory factory = new DiskFileItemFactory();
   ServletFileUpload upload = new ServletFileUpload(factory);
   List items = null;
   try {
   items = upload.parseRequest(request);
   } catch (FileUploadException e) {
   e.printStackTrace();
   }
   Iterator itr = items.iterator();
   while (itr.hasNext()) 
	   {
   FileItem item = (FileItem) itr.next();
   if (item.isFormField())
	   {
	      String name = item.getFieldName();
		  String value = item.getString();
		  if(name.equals("emp_name"))
	           {
			   emp_name=value;
            		 count1=1;
			   }
			  if(name.equals("address1"))
	                  {  
				         address1=value;            		 
                         count2=2;
					  }
			  if(name.equals("address2"))
	                  {  
				         address2=value;            		 
                         count5=5;
					  }
			  if(name.equals("contact_number"))
	                  {
			         emp_c_number=value;
			         count3=3;
					  }
            		 
			  if(name.equals("email_id"))
	             {
			      count4=4;
				  emp_emailid=value;
				 }	    
		 
		 
		    
   } else
	   {
    try {
	
   String itemName = item.getName();
   File savedFile = new File(config.getServletContext().getRealPath("/")+"emp_image\\image\\"+itemName);
   item.write(savedFile);
     %><center></table><table ><tr><td width="210"></td><td> <img  border="2" src=image/<%=itemName %> width="137"  height="140"></td></tr></table><table border="2" width="350">
   
   <% if(count1==1)
      		 out.println("<tr><td align='left'><b>Name:</td><td><b>"+emp_name);
	  if(count2==2)	 
		     out.println("</td><tr><td align='left'><b>Addresss:</td><td><b>"+address1);
	  if(count5==5)	 
		     out.println("</td><tr><td align='left'><b></td><td><b>"+address2);
	  if(count3==3)
		     out.println("</td><tr><td align='left'><b>Contact No</td><td><b>"+emp_c_number);
	  if(count4==4)
		     out.println("</td><tr><td align='left'><b>Email ID</td><td><b>"+emp_emailid);
   } catch (Exception e) {
   e.printStackTrace();
   }
   }
   }
   }
   %>
     </td></tr></table></center>

Read the error messages:
Only a type can be imported. org.apache.commons.fileupload.disk.DiskFileItemFactory resolves to a package

Since DiskFileItemFactory is a package, you know that it cannot be imported like that.
Packages are imported like this:
org.apache.commons.fileupload.disk.DiskFileItemFactory.*

Example:
java.util.*
or
java.util.Date

NOT:
java.util

Read the error messages:

Only a type can be imported. org.apache.commons.fileupload.disk.DiskFileItemFactory resolves to a package

Since DiskFileItemFactory is a package, you know that it cannot be imported like that.
Packages are imported like this:

org.apache.commons.fileupload.disk.DiskFileItemFactory.*

Example:

java.util.*

or

java.util.Date

NOT:

java.util

end quote.

sir, thanks for replay
but i still facing a problem
like below

i think fileupload package is not found can i know how to download that and configure it ..?
plz help

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: 20 in the jsp file: /employee_upload_profile_image.jsp
ServletFileUpload cannot be resolved
17:      int count1=0,count2=0,count3=0,count4=0,count5=0;
18:  %>
19:  <%
20:  boolean isMultipart = ServletFileUpload.isMultipartContent(request);
21:  if (!isMultipart) {
22:  } else {
23:    FileItemFactory factory = new DiskFileItemFactory();


An error occurred at line: 23 in the jsp file: /employee_upload_profile_image.jsp
DiskFileItemFactory cannot be resolved to a type
20:  boolean isMultipart = ServletFileUpload.isMultipartContent(request);
21:  if (!isMultipart) {
22:  } else {
23:    FileItemFactory factory = new DiskFileItemFactory();
24:    ServletFileUpload upload = new ServletFileUpload(factory);
25:    List items = null;
26:    try {


An error occurred at line: 24 in the jsp file: /employee_upload_profile_image.jsp
ServletFileUpload cannot be resolved to a type
21:  if (!isMultipart) {
22:  } else {
23:    FileItemFactory factory = new DiskFileItemFactory();
24:    ServletFileUpload upload = new ServletFileUpload(factory);
25:    List items = null;
26:    try {
27:    items = upload.parseRequest(request);


An error occurred at line: 24 in the jsp file: /employee_upload_profile_image.jsp
ServletFileUpload cannot be resolved to a type
21:  if (!isMultipart) {
22:  } else {
23:    FileItemFactory factory = new DiskFileItemFactory();
24:    ServletFileUpload upload = new ServletFileUpload(factory);
25:    List items = null;
26:    try {
27:    items = upload.parseRequest(request);


Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:457)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:367)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:345)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:332)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:342)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

Usually from where you got the example, there should be some link where you can download the jar. You can also search the net.
Don't forget though to add the jar to your classpath

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.