| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Member Join Date: Jun 2005
Posts: 38
![]() | The simplest servlet example...& I can't understand it I simply cannot understand servlets....I have something very simple to do and I can't figure it out. And it eats me inside. Although I read tutorials and everything I still can't figure it out. I downloaed apache-tomcat-5.5.15 and j2re1.4.2_01 Both are installed in C:\apache-tomcat-5.5.15-src and C:\java and I have this servlet: import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class SimpleCounter extends HttpServlet { int count = 0; ????: NamePros.com http://www.namepros.com/programming/179381-simplest-servlet-example-i-cant-understand.html public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); count++; out.println("Since loading, this servlet has been accessed " + count + " times."); } } Simple question..how do I run it? Because I have no clue whatsoever on how to run it. I can't even understand how HelloWorld servlet runs....and thats the easiest one as I understand. Pls help me cause I'm going nuts. The Helloword examples work so I guess both tomcat and java are installed corectly. |
| |
| | #2 (permalink) |
| NamePros Regular Join Date: Mar 2006
Posts: 397
![]() | Tomcat etc Add your servlet (jsp file) in ROOT directory from webapps. If you already see the the welcome message (with tomcat and stuff) try to access your site somehting like : 1. if you have http connector http://server:8082/name.jsp 2. or you are using a connector (mod jk2 or proxy) http://server/name.jsp where name.jsp is the name of your code file. Best Rergards Adrian Only now I see you have a simple class defined. you can compile as bean this class and after (add somwhere in the path of java I suggets to add your class to WEB-INF/classes /etc) thatn you need to write a jsp to access this class. Best Regards A |
| |
| | THREAD STARTER #3 (permalink) |
| NamePros Member Join Date: Jun 2005
Posts: 38
![]() | Still doesn't work. I'm trying to do this every step at the time. As I read in the the book the simplest way to run a servlet is to so save the .java or .class file to ../webapps/web-inf/classes (in my case Root/web-inf/classes as I'm using tomcat 5.0.28) and the type in the browser http://localhost:8080/servlet/SimpleCounter(or the name of your file). This is exactly what I did and it doesn't work. I get: HTTP Status 404 - /servlet/SimpleCounter type Status report message /servlet/SimpleCounter description The requested resource (/servlet/SimpleCounter) is not available. Apache Tomcat/5.0.28 can't anybody figure out what am I doing wrong? |
| |