File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes related to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "related to servlet" Watch "related to servlet" New topic
Author

related to servlet

harpreet singh sandhu
Greenhorn

Joined: Oct 11, 2008
Posts: 2
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

Joined: May 26, 2003
Posts: 30789
    
157

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
Consider Paul's rocket mass heater.
 
subject: related to servlet