Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-07
7
Medium Priority
?
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This article is about some of the basic and important steps to be used to improve the performance in web-sphere commerce application development. 1) Always leverage the Dyna-caching facility provided by the product 2) Remove the unwanted code …
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.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

721 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