• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unable to run a simple servlet program

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am trying to run a simple servlet program.
I have installed J2SE v6 on my computer and my compiler complains that it is not able to find package javax.servlet.* ;


Can anyone provide me some solution to move on.

do I have to install J2EE on my computer?


Thanks.

-Vikas
 
vikas Gourishetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's the program looks like.



package ServletExamples;
import java.io.*;

public class HelloHTML extends javax.servlet.http.HttpServlet
{
public void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException

{
response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("<HTML>\n" +
"<HEAD>\n" +
"<TITLE>Hello HTML Sample</TITLE>\n" +
"</HEAD>\n" +
"<BODY>\n" +
"<H1>Hello HTML Sample</H1>\n" +
"</BODY>\n" + "</HTML>");
}

public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws
javax.servlet.ServletException, java.io.IOException
{
doGet(request, response);
}
}
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Servlet API is not part of Standard Edition Java. And if you are just interested in Servlets and JSP rather than all the other myriad EE technologies, you can just download a servlet container such as Tomcat and it will provide the necessary jar files. That will be a lot less confusing than all of JEE.

If you want to get into EJBs or other EE technologies (probably not, at this point), then you'll need JEE.
 
vikas Gourishetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bibeault,

Thank you. So I understand the problem now.

I am trying to run the program on eclipse IDE for java EE.

The problem I see is:

"Import javax.servlet cannot be resolved"



Thank you.

-Vikas
 
Ranch Hand
Posts: 147
Eclipse IDE Tomcat Server Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the Eclipse IDE, you need to install a server runtime, like Apache Tomcat (servlets & jsp only) or Glassfish (full JEE stack).

There is an old article on installing Tomcat in Eclipse, but the information is still relevant. Installing Glassfish (or Geronimo), can be done in a similar manner, if you need a full JEE stack. Tomcat should be enough to solve your immediate issue.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vikas Gourishetty wrote:Hi Bibeault,

Thank you. So I understand the problem now.

I am trying to run the program on eclipse IDE for java EE.

The problem I see is:

"Import javax.servlet cannot be resolved"



Thank you.

-Vikas



Download tomcat. Look for j2ee.jar and include it in your classpath.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me like this post would get more attention from people that can help in the IDEs forum. I've moved it there for you.
 
vikas Gourishetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank all.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic