• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

related to servlet

 
harpreet singh sandhu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i m harpreet here as software developer. my problem is related to servlet...i m trying to import own class in servlet class...exception fired like that can not fine symbol.i m sending the code.........

abc.java
-----------
class abc
{
int i=10;
public int getd()
{
return i;
}
}

javaer.java
--------------
import abc;


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class javaser extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<body>");
abc ob=new abc();
int k=ob.getd();
out.println("<h1>Servlet test</h1>");
out.println("</body>");
out.println("</html>");
}
}

error...............



F:\servlet>javac -classpath "servlet-api.jar" javaser.java

F:\servlet>javac -classpath "servlet-api.jar" javaser.java
javaser.java:1: '.' expected
import abc;
^
javaser.java:1: ';' expected
import abc;
^
javaser.java:3: class, interface, or enum expected
import java.io.*;
^
3 errors
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34974
379
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Harpreet,
I don't think you can import classes in the default package since Java 1.4. You could put "abc" in a package. And then in import that. Some more details on imports.

Two other things:
1) "abc" is not in your classpath. You'll want something like:
javac -classpath ",;servlet-api.jar" javaser.java
2) It's traditional to have classes start with an upperclass name. So you'd have Abc and Javaser. This isn't causing your problem - it's just a good habit to get into.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic