|
Servlet example for printing random values
|
|
12-12-2011, 06:48 PM
(This post was last modified: 12-12-2011 07:16 PM by rajasri.)
Post: #1
|
|||
|
|||
|
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class colorservlet extends HttpServlet { public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException { String color=request.getParameter(”color”); response.setContentType(”text/html”); PrintWriter pw=response.getWriter(); pw.println(”The selected color is:”); pw.println(color); pw.close(); } } Step1: To run servlet You need to compile it first for that you need any of the Jar files given below 1.servlet-api.jar (included in tomcat/lib) In order to view links, you must have to reply to this thread. or 2.Jsdk.jar(included in jsdk2.0 or later) In order to view links, you must have to reply to this thread. After downloading installed it and give classpath for example if you are installing it in the c:/tomcat 5.5/” then you had to assign classpath as set classpath=c:/tomcat5.5/common/lib/servlet-api.jar;and now compile your program asusual like javac colorservlet.java. Step2: To run serlvet you need to create a web.xml file sample web.xml file for helloworld Quote:<web-app> Now create colorservlet.html Quote:<html> Your folder structure will look below colorservlet folder(inside webapps of tomcat installation folder)inside coloservlet folder it look like below. =>WEB-INF=>classes=>class files of servlet =>lib(jar files servlet-api.jar) =>web.xml =>colorservlet.html Step3 : goto http://localhost:8080/colorservlet/ and run the program Happy coding |
|||
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
|
« Next Oldest | Next Newest »
|
![]() |
|||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
User(s) browsing this thread: 1 Guest(s)






![[-]](images/royal_red/collapse.gif)






