Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2009-04-07
7
Medium Priority
?
466 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 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Upgrading Tomcat – There are a couple of methods to upgrade Tomcat is to use The Apache Installer is to download and unzip and run the services.bat remove|install Tomcat6 Because of the App that we are working with, we can only use Tomcat 6.…
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 different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

971 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