Reputation: 1993
I have a servlet. I'm new in java. But i need to run the servlet. It has two methods:
public void doGet (HttpServletRequest request,
HttpServletResponse response) {...}
and
public void doPost HttpServletRequest request,
HttpServletResponse response) {...}
What steps i need to do to run the servlet? (I have tomcat 7 installed, eclipse SE with tomcat plugin, netBeans)
Upvotes: 8
Views: 27289
Reputation: 2527
I suggest you that :
This is the quickest way to run a servlet. have fun.
Upvotes: 3
Reputation: 330
This is very basic question dude!
You can learn how to do it on Eclipse with this Tutorial link.
Please try learning from some nice books. Many nice Java EE books are available on the market.
Or you can learn Java EE from the oracle Site as well.
Upvotes: 1
Reputation: 6111
Internally call to doGet and doPost will reach like below,
Client ----------------------------> Container
sends request |
|
Creates HttpServletRequest HttpServletResponse objects
|
|
Create Thread for that Servlet and pass above objects to it
|
|
Thread Call the Service() method and decision is made to call doGet() or doPost()
|
|
doGet()/doPost() called
Upvotes: 4
Reputation: 2239
HttpServlet
and override the method doGet
and doPost
, write your business logic in thereConfigure web.xml
, something like :
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>test.helloworld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/helloworld</url-pattern>
</servlet-mapping>
Deploy your web project in the tomcat
localhost:8080/mywebapp/helloworld.do
in the browser's address bar, mywebapp
is your project nameIf you are lucky, you will see the result.
Upvotes: 8
Reputation: 1983
here is an example by @BaluC
http://balusc.blogspot.in/2007/04/imageservlet.html
Upvotes: 1
Reputation: 2222
It seems that you know little about Java EE and Servlets.
Basically, you need to write a web.xml file, which will map an URL to your servlet, build the project, create a web archive (WAR), deploy it on server.
Here's the official manual from Oracle: http://docs.oracle.com/javaee/6/tutorial/doc/bnadp.html.
Try to google for using servlets on tomcat, you will surely find a good tutorial on that.
Upvotes: 2
Reputation: 240956
Create a java web project with a IDE (Netbeans/eclipse) add a servlet to the project, It will make your life easier
Upvotes: 2