aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Unable to run a simple servlet program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Unable to run a simple servlet program" Watch "Unable to run a simple servlet program" New topic
Author

Unable to run a simple servlet program

vikas Gourishetty
Ranch Hand

Joined: Aug 20, 2010
Posts: 38
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

Joined: Aug 20, 2010
Posts: 38
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);
}
}
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
vikas Gourishetty
Ranch Hand

Joined: Aug 20, 2010
Posts: 38
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
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

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.


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6662
    
    5

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.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

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

Joined: Aug 20, 2010
Posts: 38
Thank all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to run a simple servlet program