Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to test my servlet

 
S Varana
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

<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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it.
Thanx eram
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic