aspose file tools*
The moose likes Servlets and the fly likes servlet is not executing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet is not executing" Watch "servlet is not executing" New topic
Author

servlet is not executing

Soni Mitesh
Ranch Hand

Joined: Sep 02, 2007
Posts: 33
Hi Ranchers,
i am creating simple servlet, but some reason it is not running, the code and procedure i m writing here, tell me what is wrong and how to rectify it.
Thanks.


tomcat/webapps/MyServ/WEB-INF/src/HowdyServlet.java
tomcat/webapps/MyServ/WEB-INF/web.xml
tomcat/webapps/MyServ/WEB-INF/classes/HowdyServlet.class

//HowdyServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HowdyServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{
PrintWriter out=res.getWriter();
res.setContentType("text/html");
out.println("<html>");
out.println("<body>");
out.println("<center><h1>Howdy</h1></center>");
out.println("</body>");
out.println("</html>");
}
}

---------------
//web.xml
<web-app>
<servlet>
<servlet-name>HowdyServlet</servlet-name>
<servlet-class>HowdyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HowdyServlet</servlet-name>
<url-pattern>HowdyServlet</url-pattern>
</servlet-mapping>
</web-app>

--------------
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Originally posted by Soni Mitesh:

tomcat/webapps/MyServ/WEB-INF/src/HowdyServlet.java
tomcat/webapps/MyServ/WEB-INF/web.xml
tomcat/webapps/MyServ/WEB-INF/classes/HowdyServlet.class

Why is your source under WEB-INF? Move it to outside the web app. It's just taking up unnecessary space.

Also, all servlets and other Java classes should be in packages other than the default.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Soni Mitesh
Ranch Hand

Joined: Sep 02, 2007
Posts: 33
Also, all servlets and other Java classes should be in packages other than the default.
-----------------------

thanks bear,
but the doubt is not cleared.
I have removed the SRC from the WEB-INF
and i am not keeping the servlet in default package.
under webapps i did create the directory for servlet program
it would be great if you could elaborate the clarification.

thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61612
    
  67

Originally posted by Soni Mitesh:
and i am not keeping the servlet in default package.

Yes, you are. What package do you think that the servlet is in?
kamalkant rajput
Greenhorn

Joined: Nov 26, 2007
Posts: 22
if you can what error you are getting then only we can help you.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

http://www.coderanch.com/t/365578/Servlets/java/error-servlet
I have had the same discussion recently. Personally I'd like to see the Servlet packaged correctly before I tried looking for other issues.
Soni Mitesh
Ranch Hand

Joined: Sep 02, 2007
Posts: 33
Thank you, all...
but i have got the solution...
the problem was with the web.xml file
in url-pattern tag i typed wrong ...
<url-pattern>HowdyServlet</url-pattern>
instead this i had to write the below given line...
<url-pattern>/HowdyServlet</url-pattern>
x()
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet is not executing