The moose likes Servlets and the fly likes How to test my servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to test my servlet" Watch "How to test my servlet" New topic

How to test my servlet

S Varana

Joined: Feb 04, 2004
Posts: 18

import javax.servlet.*;
import javax.servlet.http.*;
public class HW extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
PrintWriter out = response.getWriter();
out.println("<title>Hello World Good Day!!!</title>");
out.println("<h1>Hello World!</h1>");
I am having JSWDK1.0.1
This is my servlet program.
It has compiled well but i don't know how to run it.
Now please tell me how to view the output and test my servlet.
Ranch Hand

Joined: Mar 14, 2000
Posts: 38
Start the server and run from:
http:\\localhost ort-num\path-to-servlets\servlet-name
S Varana

Joined: Feb 04, 2004
Posts: 18
Thanks for your reply Eram. I tried what U said but stil ....
Actually this is the directory structure
"E:\servlets\jswdk-1.0.1\webpages\WEB-INF\servlets" under which I have my .class "HW".
I tried with all combination after the http://localhost:8080/
Ex: http://localhost:8080/jswdk-1.0.1/webpages/WEB-INF/servlets,
http://localhost:8080/webpages/WEB-INF/servlets and so on.....
Also I do have added an entry in the "" file like this "HW.code=HW"(And nothing else in the other .properties file).
After compiling the java file, can U tell me what all I need to take care(like adding into .properties file, placing the .class in which directory...)?
Is that I am missing anything else? Please let me know.
Thank U.
Ranch Hand

Joined: Mar 14, 2000
Posts: 38
Newbie -
1. store your .java files and .class file in jsdk\examples\web-inf\servlets\
2. run your server using startserver.bat
3. execute your servlets using:
carefully watch at the above path for running your examples.
If u cahnge or compile ur servlets , top and restart the server and also refresh the pgaes to see the results.
infact http:\\localhost:8080\ acts like your local intranet, which means u can browse any html files using above stuff.
just type in http:\\localhost:8080\index.html - u will get a page.
keep trying newbie..........have fun.
S Varana

Joined: Feb 04, 2004
Posts: 18
I got it.
Thanx eram
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi newbie and eram,
I have the same problem running the servlet, could you please let me know what changes did you make in the properties file and where die you put u'r .java and .class files(which dir and where) If i open the servlet in the webpage, i get an error saying
File not found.
Please let me know.
I agree. Here's the link:
subject: How to test my servlet
It's not a secret anymore!