LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-19-2008, 05:14 AM   #1
abd_bela
Member
 
Registered: Dec 2002
Location: algeria
Distribution: redhat 7.3, debian lenny
Posts: 591

Rep: Reputation: 31
no servlet class on sun-java6 ?


Hi,
I have installed sun-java6 on debian lenny.
I took a program ( using servlet ) from a book, so I suppose it runs correctly, I tried it on my PC using sun-java6. Does it have another name?
Other programs, with (swing, applet ...), run correcly.
I searched servlet class in javax, I didn't find it
the error is at the import javax.servlet.*; import javax.servlet.http.*;

here is the example

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CalculPerimeter extends HttpServlet {
public void doGet( HttpServletRequest req, HttpServletResponse rep)
throws IOException, ServletException {
rep.setContentType("text/html");
PrintWriter pw = rep.getWriter();
pw.println("<html>");
pw.println("<head>");
pw.println("<title> Just a servlet </title>");
pw.println("</head>");
pw.println("<body bgcolor='white'>");
if (req.getParameter("ray") == null) {
pw.print("<font size=+1> ");
pw.println(" need to know the value of the ray!</font>");
}
else {
int tmp=Integer.parseInt(req.getParameter("ray"));
Circle C = new Circle(0, 0, tmp);
double p = C.perimeter();
pw.println("The ray is "+tmp+"perimeter "+ p);
}
pw.println("</body>");
pw.println("</html>");
}
}

The Circle class is of couse defined.
Thanks for help
 
Old 10-19-2008, 06:07 AM   #2
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Quote:
Originally Posted by abd_bela View Post
Hi,
I have installed sun-java6 on debian lenny.
I took a program ( using servlet ) from a book, so I suppose it runs correctly, I tried it on my PC using sun-java6. Does it have another name?
Other programs, with (swing, applet ...), run correcly.
I searched servlet class in javax, I didn't find it
the error is at the import javax.servlet.*; import javax.servlet.http.*;

here is the example

Code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CalculPerimeter extends HttpServlet {
    public void doGet( HttpServletRequest req, HttpServletResponse rep)
	        throws IOException, ServletException {
	 rep.setContentType("text/html");
	 PrintWriter pw = rep.getWriter();
	 pw.println("<html>");
	 pw.println("<head>");
	 pw.println("<title> Just a servlet </title>");
	 pw.println("</head>");
	 pw.println("<body bgcolor='white'>");
	 if (req.getParameter("ray") == null) {
		pw.print("<font size=+1> ");		
		pw.println(" need to know the value of the ray!</font>");
	 }
	 else {
		int tmp=Integer.parseInt(req.getParameter("ray"));
		Circle C = new Circle(0, 0, tmp);
		double p = C.perimeter();
		pw.println("The ray is "+tmp+"perimeter "+ p);
	 }
	 pw.println("</body>");
	 pw.println("</html>");
    }
}
The Circle class is of couse defined.
Thanks for help
You will need to add servlet.jar to your classpath. If you download apache-tomcat, you will have that jar within the "lib" folder of Tomcat.

Personally, I would recommend you to download "Eclipse IDE for Java EE Developers", so you don't have to worry about those things . Netbeans actually even helps you to install Tomcat and/or Glassfish during installation. A big help indeed. I know recommending an IDE sounds overkill, but Servlets and JSP are a complex matter. It gets even more tough when you put in some frameworks like Hibernate or Struts. You will need an IDE, so you better off start with one, IMHO.

P.S: in the future, when posting code, please use the <code> tags as I just did. Makes it much easier on the eyes

Last edited by Mega Man X; 10-19-2008 at 06:11 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
installing sun-java6-jdk dcbc Linux - Software 2 04-02-2008 07:17 AM
C++ templated Node class: pointers to different instantated class types jhwilliams Programming 3 08-20-2007 06:20 PM
updated to java6, can't connect to jirc/jchat gutty96 Linux - Newbie 0 06-26-2007 04:49 PM
Does derivated class inherit base class destructor (constructor)? kornerr Programming 2 08-23-2006 08:05 AM
Which C++ editor in Linux has the class view/class browser feature imaginationworks Programming 7 05-21-2006 11:09 PM


All times are GMT -5. The time now is 04:52 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration