This is a discussion on servlets within the Java Server Pages (JSP) forums, part of the Web Development category; If I already have servlets why would I need to use JSP technology for? What are some main addition of ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| JavaServer Pages (JSP) technology is the Java platform technology for delivering dynamic content to web clients in a portable, secure and well-defined way. The JavaServer Pages specification extends the Java Servlet API to provide web application developers with a robust framework for creating dynamic web content on the server using HTML, and XML templates, and Java code, which is secure, fast, and independent of server platforms. JSP has been built on top of the Servlet API and utilizes Servlet semantics. JSP has become the preferred request handler and response mechanism. Although JSP technology is going to be a powerful successor to basic Servlets, they have an evolutionary relationship and can be used in a cooperative and complementary manner. Servlets are powerful and sometimes they are a bit cumbersome when it comes to generating complex HTML. Most servlets contain a little code that handles application logic and a lot more code that handles output formatting. This can make it difficult to separate and reuse portions of the code when a different output format is needed. For these reasons, web application developers turn towards JSP as their preferred servlet environment Thanks Ragav |
| |||
| Thanks Ragav, Can you give a sample program about the servlet object and how it will be used in web applications? It will be better tp give the client source and servlet object with a sample program. thanks ![]()
__________________ Karpagarajan. R Necessity is the mother of invention |
| |||
| Quote:
I have written a Sample program in servlets //#--Server Side Programm example1.java import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class Hello extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); String param = request.getParameter("param"); if (param != null) out.println("Thanks for Ur Visit ='" + param + "'!!!!"); } } //#-- Client Side <FORM METHOD="GET" ACTION="http://localhost.8080/cgi-bin/servletrun/example1"> <TR><TD>Name:</TD><TD><INPUT NAME="param" size="50"></TD> </TR> <TR><TD><input type="submit" name="ClickMe" value="ClickMe"></TD></TR> </FORM> above program just print a String what ever u give value in text box Thanks Ragav |
| |||
| import java.io.*; import java.text.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import util.HTMLFilter; /** * Example servlet showing request headers * */ public class RequestHeaderExample extends HttpServlet { ResourceBundle rb = ResourceBundle.getBundle("LocalStrings"); public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<body bgcolor=\"white\">"); out.println("<head>"); String title = rb.getString("requestheader.title"); out.println("<title>" + title + "</title>"); out.println("</head>"); out.println("<body>"); // all links relative // XXX // making these absolute till we work out the // addition of a PathInfo issue out.println("<a href=\"../reqheaders.html\">"); out.println("<img src=\"../images/code.gif\" height=24 " + "width=24 align=right border=0 alt=\"view code\"></a>"); out.println("<a href=\"../index.html\">"); out.println("<img src=\"../images/return.gif\" height=24 " + "width=24 align=right border=0 alt=\"return\"></a>"); out.println("<h3>" + title + "</h3>"); out.println("<table border=0>"); Enumeration e = request.getHeaderNames(); while (e.hasMoreElements()) { String headerName = (String)e.nextElement(); String headerValue = request.getHeader(headerName); out.println("<tr><td bgcolor=\"#CCCCCC\">"); out.println(HTMLFilter.filter(headerName)); out.println("</td><td>"); out.println(HTMLFilter.filter(headerValue)); out.println("</td></tr>"); } out.println("</table>"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Advantages of JSP over servlets | lavanya | Java Server Pages (JSP) | 4 | 03-19-2008 06:46 AM |
| What is the use of Servlets ? | oxygen | Java Programming | 3 | 08-07-2007 12:59 AM |