• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
1
SATEESH N
For many WEB applications server side processing is necessary. i.e., whenever a WEB Browsersends the data to a WEB Server the WEB Server forwards the same to a program on the server which isreferred as ServerSideProgram. The ServerSideProgram receives the data form the WEB Server, process thedata and returns the output back to the WEB Server which will be given to the WEB Browser. The WEBBrowser receives the data and presents the data on the document. These ServerSidePrograms can be writtenin any language such as C, C++, UNIX Shell programming, perl, Servlets etc., and the current technologiesthe ServerSidePrograms are designed using ASP,JSP etc.,
WEB Browser
http://yahoo.comUser NamePassword
YahooWEB Server
Login
checkmail
Particular ID’s Mail Box
Documents
deletewill be opened
The following are the famous
WEB servers :
IIS (Internet Information Serverm )
à
MircroSoft
à
supports ASPPWS ( Personal WEB Server )
à
MircroSoft
à
supports ASPApache
à
Apache
à
only for HTMLTomcat
à
Jakarta
à
supports servlets,,jsp, tomcat doesn’t supports for EJB. http://apache.jakarta.orgJava Web Server
à
J2EE
à
Weblogic
à
BEAWebsphere
à
IBMJRun
à
JBoss
à
etc.,
Methods of sending data :
A WEB Browser after receiving the details from the user cab forward to the WEB Server in any of thefollowing 3 methods.GETPOSTHEADA WEB Server after receiving the data from the WEB Browser should forward the same to the ssp inthe following 3 corresponding methods.GET Environment variablesPOST StreamsHEAD Commandline argumentsServerSideProgram
 
2
SATEESH N
GET Environment variablesPOST StreamsHEAD Commandline args
URL Coding :
Whenever a WEB Browser is required to send data to the WEB Server the WEB Browserconverts the data in a particualar format, which is known as URL coding. The server isde program receives theconverted data undos the conversion and process the data.The following 4 rules will be used by the WEB Browsers for URL coding.1. All the fields will be separated by & symbol.2. Each field contains the name of the field and the value of the field separated by = symbol.3. All spaces will be converted to + symbols.4. All special characters such as +, & etc., will be converted to hexadecimal values prefixed with %symbol.Ex:http://myserver.com/SSPname?Empno=101&Ename=abc+xyz&Job=clk%xxAccServer ssp param1 value1 p2 v2 p3 v3In Java the SSPs can be written in sevlets and jsp.
Creating a Servlet :
To create a servlet create a class that extends the “HttpServlet” class and overrideany or both of the following methods (i) doGet( ) (ii) doPost( )
à
If the WEB Browser sends the data in the “Get( ) “ method then “doGet( )” method of servlet will beexecuted.
à
If the WEB Browser sends the data in the “Post” method then the “doPost( )” method of the servletwill be execued.
à
If the WEB Browser doesnot specify any method, then the “doGet( )” will be executed.Syntax :DoGet( ) : public void doGet(HttpServletRequest, HttpServletResponse) throws ServletException,IO ExceptionDoPost( ):public void doPost(HttpServletRequest,HttpServletResponse) throws ServletException,IO ExceptionThe “request” object contains the data that was received from the WebBrowser and the “response”allows us to send the output back to the WebBrowser.While exchanging data between the WEB Browser and WEB Server the following 2 objects are used:Request and Response.tomcatrequestresponse
user name :password :Login
WEB ServerServer Side Program
user name :password :Login
WEB ServerServer Side Program
 
3
SATEESH N
HttpServletRequest :
For receiving input from the WebBrowser.Methods :String getParameter(String paramname) : Returns the value of the specified parameter. It returns null if theparameter is not available.Cookie[ ] get Cookie( ) : Returns all the cookies that are received from the WebBrowser.HttpSession getSession( ) : Returns the current HttpSession.
HttpServletResponse :
For sending output to the WebBrowser.Methods :void setContentType(String mimeType) : Sets the content type as mime type.MIME(Multipurpose Internet Mail Extension )Mime Types : text/html text/plain image/gifPrintWriter getWriter( ) : Returns the output stream for sending the output to thye WebBrowser.void addCookie(Cookie ck) : Sends a cookie to the WebBrowser. // w.a.Servlet to send the text to WebBrowser. // File name :
firstservlet.java
import java.io.*;import javax.servlet.*;import javax.servlet.http.*;public class firstservlet extends HttpServlet{public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{// send the output to the webbrowserresponse.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<HTML>");out.println("<BODY bgcolor=#0086b2 text=white>");out.println("<H1 align =center>Welcome to Servlet Programming</H1>");out.println("<HR size=5 color=black>");out.println("<H3> First Servlet Program</H3>");out.println("</BODY>");out.println("</HTML>");}}
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...