aspose file tools*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to test my servlet" Watch "How to test my servlet" New topic
Author

How to test my servlet

S Varana
Greenhorn

Joined: Feb 04, 2004
Posts: 18

<pre>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HW extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World Good Day!!!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
}
</pre>
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.
eram
Ranch Hand

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

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 "servlets.properties" 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.
eram
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:
http:\\localhost:8080\examples\servlet\servlet-name
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
Greenhorn

Joined: Feb 04, 2004
Posts: 18
I got it.
Thanx eram
Anonymous
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
Error:404
File not found.
Please let me know.
Thanks,
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to test my servlet