Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A servlet program not running successfully

 
Rohit Rawat Om
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a beginner to Servlets and I was running my first servlet program. Its a very simple code as shown below.



After compiling the result is " import javax.servlet.*; and import javax.servlet.http.*; packages do not exist. Other errors are there but they are related to these two.
jdk 1.6 is installed on my pc and I've done all the settings like setting environment and all and other prgms are successgully running.
When I unzipped the src file I found no servlet subpackage inside javax package. Is the problem because of this? If yes then how to get the servlet subpackage?
And what could be the other problem(s)?
Please help and thanks a lot in advance.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

For starters, you shouldn't extend GenericServlet, you should extend HttpServlet, and you shouldn't override service, but doGet or doPost.

The problem is that you need to add the servlet API jar file to your classpath. Since that is not part of JSE -as you've found out- you'll need to obtain it elsewhere. If you download JEE then it's included in that, or any servlet container (like Tomcat) also has it. You'll need a servlet container anyway to run servlets, so that's probably the easiest choice.
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also Rohit Use Code Tags when you post a source code. That way your code looks formatted. Unformatted code is hard to read. You can add code tags by wrapping your code in [code] [/code] tags. You can edit your message using button and then add code tags to it...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic