NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page The simplest servlet example...& I can't understand it

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 03-22-2006, 04:33 AM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Jun 2005
Posts: 38
Biggie_mac is an unknown quantity at this point
 



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.
Biggie_mac is offline  
Old 03-22-2006, 08:10 AM   #2 (permalink)
NamePros Regular
Join Date: Mar 2006
Posts: 397
sacx13 is on a distinguished road
 



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
sacx13 is offline  
Old 03-23-2006, 03:37 AM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Jun 2005
Posts: 38
Biggie_mac is an unknown quantity at this point
 



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?
Biggie_mac is offline  
Old 03-31-2006, 04:22 AM   #4 (permalink)
NamePros Regular
Join Date: Mar 2006
Posts: 397
sacx13 is on a distinguished road
 




Just delete the content of your work directory and restart your tomcat !

Do you see the tomcat welcome page ?

Regards
sacx13 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:57 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger