[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 03-22-2006, 03:33 AM   #1 (permalink)
NamePros Member
 
Join Date: Jun 2005
Posts: 38
64.00 NP$ (Donate)

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;

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, 07:10 AM   #2 (permalink)
NamePros Regular
 
Join Date: Mar 2006
Posts: 394
211.38 NP$ (Donate)

sacx13 is on a distinguished road


Arrow 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, 02:37 AM   #3 (permalink)
NamePros Member
 
Join Date: Jun 2005
Posts: 38
64.00 NP$ (Donate)

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, 03:22 AM   #4 (permalink)
NamePros Regular
 
Join Date: Mar 2006
Posts: 394
211.38 NP$ (Donate)

sacx13 is on a distinguished road


Lightbulb

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:35 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85