Results 1 to 2 of 2
  1. #1
    ricky_40 is offline Member
    Join Date
    Mar 2010
    Rep Power

    Default Help with servlet error message


    I'm getting an error message in my servlet code. Can't seem to figure it. Would appreciate any help.

    Error message:

    java.lang.Error: Unresolved compilation problems:
    void is an invalid type for the variable processFileItem
    Syntax error on token "(", ; expected
    Syntax error on token ")", ; expected

    javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)

    Servlet Code:


    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.tomcat.util.http.fileupload.DefaultFile ItemFactory;
    import org.apache.tomcat.util.http.fileupload.FileItem;
    import org.apache.tomcat.util.http.fileupload.FileUpload;
    import org.apache.tomcat.util.http.fileupload.FileUploadE xception;

    * Servlet implementation class UploadServlet
    public class UploadServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    * @see HttpServlet#HttpServlet()
    public UploadServlet() {
    // TODO Auto-generated constructor stub

    * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    private void processFileItem(FileItem item){
    // Can access all sorts of useful info. using FileItem methods
    if (item.isFormField()) {
    // TODO process input field of form depending on the field name!
    } else {
    // Is an uploaded file, so get name & store on local filesystem
    String uploadedFileName = new File(item.getName()).getName();
    File savedFile = new File("c:/uploads/"+uploadedFileName);
    try {
    item.write(savedFile);// write uploaded file to local storage
    } catch (Exception e) {
    // Problem while writing the file to local storage


    * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    // Check that we have a file upload request
    if ( FileUpload.isMultipartContent(request) ) {
    // Create a new file upload handler
    FileUpload upload = new FileUpload(new DefaultFileItemFactory());
    try {
    for (Object item : upload.parseRequest(request)) {
    processFileItem((FileItem)item);// call method to process each item
    } catch (FileUploadException e) {
    // Problem when parsing the request data: output an error message.....
    // Generate some sample HTML
    PrintWriter out = response.getWriter();


    private void processFileItem(FileItem item) {
    // TODO Auto-generated method stub



  2. #2
    raghupallaki is offline Member
    Join Date
    Jan 2010
    Rep Power


    Hi Ricky,

    As I understood in your code and as of my knowledge, we can not define a (giving method expanction) method in doGet or doPost method like private void processFileItem(FileItem item).

    Can you plz try this by removing this method and place out of doGet.

    And remove the duplicated method definition for private void processFileItem(FileItem item).

    If you want to call this method in doGet, pass FileItem obj.

    I this solution souts your problem.

    Raghu Pallaki.

Similar Threads

  1. Error Message????
    By Cubba27 in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 03:46 PM
  2. Error Message in JBuilder
    By RavenNevarmore in forum New To Java
    Replies: 4
    Last Post: 10-08-2008, 07:53 AM
  3. strange Error message
    By little_polarbear in forum New To Java
    Replies: 4
    Last Post: 08-26-2008, 12:45 AM
  4. java error message
    By baileyr in forum New To Java
    Replies: 2
    Last Post: 01-23-2008, 04:47 AM
  5. error message on jsp
    By sandor in forum Web Frameworks
    Replies: 1
    Last Post: 04-11-2007, 03:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts