Solved

can you tell me why this class doesn't get compiled

Posted on 2009-04-07
7
437 Views
Last Modified: 2013-12-02
hi all,
I'm using tomcat 6 on linux centos 5
I got this .java file for a servlet  it's code is attached
here is the compilation error message please help what is the problem and how to fix it

[root@localhost classes]# javac -classpath /opt/tomcat6/lib/servlet-api.jar -d ./ ./firstservlet.java
----------
1. WARNING in ./firstservlet.java (at line 5)
        public class firstservlet extends HttpServlet
                     ^^^^^^^^^^^^
The serializable class firstservlet does not declare a static final serialVersionUID field of type long
----------
2. ERROR in ./firstservlet.java (at line 9)
        HttpServletResponse response) throws ServletException,
                                             ^^^^^^^^^^^^^^^^
ServletException cannot be resolved to a type
----------
3. ERROR in ./firstservlet.java (at line 49)
        HttpServletResponse response) throws ServletException,
                                             ^^^^^^^^^^^^^^^^
ServletException cannot be resolved to a type
----------
4. ERROR in ./firstservlet.java (at line 53)
        Enumeration paramNames = request.getParameterNames( );
        ^^^^^^^^^^^
Enumeration cannot be resolved to a type
----------
4 problems (3 errors, 1 warning)[root@localhost classes]#





import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;
 

 public class firstservlet extends HttpServlet 

{

    

  public void doGet(HttpServletRequest request, 

    HttpServletResponse response) throws ServletException,

      java.io.IOException 

  {

    

    //set the MIME type of the response, "text/html"

    response.setContentType("text/html");

    

    //use a PrintWriter to send text data to the client who has requested the

    //servlet

    java.io.PrintWriter out = response.getWriter( );
 

    //Begin assembling the HTML content

    out.println("<html><head>");

    

    out.println("<title>Help Page</title></head><body>");

    out.println("<h2>Please submit your information</h2>");

   

   //make sure method="post" so that the servlet service method

   //calls doPost in the response to this form submit

    out.println(

        "<form method=\"post\" action =\"" + request.getContextPath( ) +

            "/firstservlet\" >");
 

    out.println("<table border=\"0\"><tr><td valign=\"top\">");

    out.println("Your first name: </td>  <td valign=\"top\">");

    out.println("<input type=\"text\" name=\"firstname\" size=\"20\">");

    out.println("</td></tr><tr><td valign=\"top\">");

    out.println("Your last name: </td>  <td valign=\"top\">");

    out.println("<input type=\"text\" name=\"lastname\" size=\"20\">");

    out.println("</td></tr><tr><td valign=\"top\">");

    out.println("Your email: </td>  <td valign=\"top\">");

    out.println("<input type=\"text\" name=\"email\" size=\"20\">");

    out.println("</td></tr><tr><td valign=\"top\">");
 

    out.println("<input type=\"submit\" value=\"Submit Info\"></td></tr>");

    out.println("</table></form>");

    out.println("</body></html>");
 

    }//doGet

  public void doPost(HttpServletRequest request, 

    HttpServletResponse response) throws ServletException,

    java.io.IOException {

    

    //display the parameter names and values

    Enumeration paramNames = request.getParameterNames( );
 

    String parName;//this will hold the name of the parameter

    

    boolean emptyEnum = false;
 

    if (! paramNames.hasMoreElements( ))

        emptyEnum = true;

    

        

    //set the MIME type of the response, "text/html"

    response.setContentType("text/html");

    

    //use a PrintWriter to send text data to the client 

    java.io.PrintWriter out = response.getWriter( );

    

    //Begin assembling the HTML content

    out.println("<html><head>");

    out.println("<title>Submitted Parameters</title></head><body>");

    

    if (emptyEnum){

        out.println(

           "<h2>Sorry, the request does not contain any parameters</h2>");

    } else {

    out.println(

        "<h2>Here are the submitted parameter values</h2>");

    }

    

    while(paramNames.hasMoreElements( )){

    

        parName = (String) paramNames.nextElement( );
 

        out.println(

            "<strong>" + parName + "</strong> : " +

                request.getParameter(parName));
 

        out.println("<br />");
 

    }//while

        

    out.println("</body></html>");

    

  }// doPost

}

Open in new window

0
Comment
Question by:hatem_from_mesr
  • 3
  • 3
7 Comments
 
LVL 7

Expert Comment

by:gudii9
ID: 24092538
check all the filed types to make sure defined correctly
0
 
LVL 16

Accepted Solution

by:
warturtle earned 500 total points
ID: 24095234
Add the following lines to correct this problem:

import javax.servlet.ServletException;
import java.util.Enumeration;

And recompile the class again. Let us know, what you get.
0
 

Author Comment

by:hatem_from_mesr
ID: 24095839
hi warturtle,
it compile but there is a warning can you tell me what to do to avoid it
[root@localhost classes]# javac -classpath /opt/tomcat6/lib/servlet-api.jar -d ./ ./firstservlet.java
----------
1. WARNING in ./firstservlet.java (at line 7)
        public class firstservlet extends HttpServlet
                     ^^^^^^^^^^^^
The serializable class firstservlet does not declare a static final serialVersionUID field of type long
----------
1 problem (1 warning)[root@localhost classes]# ls
firstservlet.class  firstservlet.java  firstservlet.java~
[root@localhost classes]#
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:hatem_from_mesr
ID: 24095862
hi gudii9,
>>>check all the filed types to make sure defined correctly
I don't understand what you say
0
 
LVL 16

Expert Comment

by:warturtle
ID: 24096646
Yes, this warning is not coming from within JDK. It is possibly coming from within an IDE like Eclipse. Have a look at the solution within this thread and see if it works for you:

http://www.experts-exchange.com/Programming/Languages/Java/Q_21186340.html

If not let me know and provide more information on the enviroment within which this program is executing like IDE and JDK exact version.
0
 

Author Closing Comment

by:hatem_from_mesr
ID: 31567790
thanks man
0
 
LVL 16

Expert Comment

by:warturtle
ID: 24113957
Thanks for the feedback and happy to be of help :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 87
compre toata in where clue oracle 4 57
couple of eclipse 5 27
table example 4 25
Most of the developers using Tomcat find it easy to configure the datasource in Server.xml and use the JNDI name in the code to get the connection.  So the default connection pool using DBCP (or any other framework) is made available and the life go…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now