• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlet is not executing

 
Soni Mitesh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Soni Mitesh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you can what error you are getting then only we can help you.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic