Solved

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

Posted on 2009-04-07
7
434 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 38
where is session ID cache stored 1 39
firstChar challenge 13 85
GUI builder for Eclipse? 8 11
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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 learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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.

762 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

16 Experts available now in Live!

Get 1:1 Help Now