By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,407 Members | 1,753 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,407 IT Pros & Developers. It's quick & easy.

How to execute java servlet using tomcat server?

P: 40
1.I installed apache tomcat.


2.I have the following java servlet

import java.io.*;
import javax.sevlet.*;
import javax.servlet.http.*;
public class ser extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text.html");
PrintWriter out=res.getWriter();

String name=req.getParameter("name");
out.println("<html>");
out.println("<body>");
out.println("hello"+name);
out.println("</body>></html>");
}

}


3.where should i put this servlet in tomcat.

4.I want clear explanation for executing javaservet using tomcat server.


please,kindly give reply for this problem.
Mar 30 '08 #1
Share this Question
Share on Google+
4 Replies


10K+
P: 13,264
1.I installed apache tomcat.


2.I have the following java servlet

import java.io.*;
import javax.sevlet.*;
import javax.servlet.http.*;
public class ser extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text.html");
PrintWriter out=res.getWriter();

String name=req.getParameter("name");
out.println("<html>");
out.println("<body>");
out.println("hello"+name);
out.println("</body>></html>");
}

}


3.where should i put this servlet in tomcat.

4.I want clear explanation for executing javaservet using tomcat server.


please,kindly give reply for this problem.
... and what does the documentation say?
Mar 31 '08 #2

P: 40
... and what does the documentation say?

I have compiled the file and placed in

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\WEB-INF\classes\


and

i opened the browser and gave the url as
http://localhost:8080/servlet/ser


but
i am getting an error called

/servlet/ser does not found.

what should i do for running the servlet.
Apr 1 '08 #3

Expert 10K+
P: 11,448
what should i do for running the servlet.
This bluntly shows that you haven't read all of the documentation. The docs also
talk about a deployment decriptor (a bit of xml) which you have to create.

kind regards,

Jos
Apr 1 '08 #4

Expert 100+
P: 392
/servlet/ser does not found.
what should i do for running the servlet.
You need to define the Servlet in deployment descriptor (web.xml) in the WEB-INF folder. If you are using an IDE like Netbeans or Eclipse you may want to look at having them create a WAR file to deploy to Tomcat.


This web.xml would let you call http://localhost:8080/myServlet
[HTML]
<?xml version="1.0"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class><<Your Class Name Here>></servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>myServlet</url-pattern>
</servlet-mapping>

<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>
[/HTML]
Apr 1 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.