Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to run a simple servlet program

 
vikas Gourishetty
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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
  • 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);
}
}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Pete Nelson
Ranch Hand
Posts: 147
Debian Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic