IT Community - Software Programming, Web Development and Technical Support

servlets

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 ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Java Server Pages (JSP)

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 03-15-2007, 06:53 PM
swoosh swoosh is offline
D-Web Programmer
 
Join Date: Mar 2007
Posts: 71
swoosh is on a distinguished road
Default servlets

If I already have servlets why would I need to use JSP technology for? What are some main addition of this technology that could make my existing sites more optimized?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-17-2007, 06:26 AM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Re: servlets

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-18-2007, 11:13 PM
Karpagarajan Karpagarajan is offline
D-Web Analyst
 
Join Date: Mar 2007
Posts: 299
Karpagarajan is on a distinguished road
Thumbs up Re: servlets

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-20-2007, 08:31 AM
ragavraj ragavraj is offline
D-Web Programmer
 
Join Date: Feb 2007
Posts: 92
ragavraj is on a distinguished road
Default Re: servlets

Quote:
Originally Posted by Karpagarajan View Post
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
Hi

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-29-2007, 06:36 AM
leoraja8 leoraja8 is offline
D-Web Sr.Programmer
 
Join Date: May 2007
Posts: 194
leoraja8 is on a distinguished road
Default Re: servlets

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);
}

}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 11:00 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0