Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Servlets & JSP

Servlets & JSP

Ratings: (0)|Views: 62 |Likes:

More info:

Published by: Sudheer Reddy Pothurai on Oct 29, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as RTF, PDF, TXT or read online from Scribd
See more
See less





According to Servlet specification a web application is a collection of web resources.There are two types of web resources. 1) static resources : - html files, xml files, jpg files …etc 2) dynamic resources : - servlet, jsp (java server page), asp (active server page), cgiprograms.Servlet based application can be developed (placed) on the servlets like Tomcat, web logic,web sphere, etc … that supports servlet API (specification).We can develop the web applications using the servlet technology that is part of javaenterprise edition. A servlet object is a java object that provides the implementation of  javax.servlet.Servlet interface.implements implementsextendsextendsextendsSOne class is not a servlet class. The object based on SOne class is not a servlet object. STwo,SThr, OurSrv classes implements the Servlet interface direct or indirectly. These classes arecalled as Servlet objects.
import javax.servlet.*;import javax.servlet.http.*;import java.io.*;public class OurSrv extends HttpServlet{public void service(HttpServletRequest request, HttpServletResponseresponse) throws ServletException, IOException{PrintWriter out=response.getWriter( );System.out.println(request.getMethod( ));System.out.println(request.getRequestURI( ));System.out.println(request.getProtocol( ));System.out.println(request.getHeader("User-Agent"));out.println("executed");}}D:\Pskr>javac OurSrv.java
6 errorsBecause the path is not set to the current directory, so copy the weblogic.jar orservlet-api.jar to the current directory & set the class path & try again compileD:\Pskr>set CLASSPATH=weblogic.jar;.D:\Pskr>javac OurSrv.javaD:\Pskr>REQUESTRESPONSEClientWeb container(Tomcat, web logic ….etc)A web container is product that supports the web application develop using servlettechnology. Web containers are developed in java language according to the servletspecification given by java soft. Some of the popular web containers are Tomcat, web logic,web sphere, sun one server, oracle application server …. Etc. All these web containerssupport the HTTP protocol. Every web container vendor provide a jar file that containsservlet related packages (javax.servlet, javax.servlet.http).
Procedure for assembling for web application
: -1) Create a WEB-ROOT directoryex: - d:\ourwapp2) Create a directory with the name WEB-INF under the WEB-ROOT directory.3) Create the following 2 directories under the WEB-INFa) Classes ---- used to place .class files b) lib --- used to place .jar files4) The static resources like html, xml, jpg etc… must be placed under WEB-ROOT or thesub directories of WEB-ROOT except WEB-INF.D:.└───ourwapp├───Sdir└───WEB-INF├───classes└───lib5) Copy the servlet classes under WEB-INF/classes directory6) Provide the web.xml (deployment descriptor) under WEB-INF directory.7) create a war file using a jar toola) open a dos window and use cd command to move to the WEB-ROOT directoryD:\Pskr>cd ourwappb) Use the following command to create a war fileD:\Pskr\ourwapp>jar cf ourwapp .
Here cf means create file & . means current directoryCopy the OurSrv.class under ourwapp\WEB-INF\classes directory.
<html><head><title>one.html</title></head><body>welcome to one.html</body></html>Copy the one.html to ourwapp or Sdir.
<web-app><display-name>My Web Application</display-name><description>info about my app</description><servlet><servlet-name>oursrv</servlet-name><servlet-class>OurSrv</servlet-class></servlet><servlet-mapping><servlet-name>oursrv</servlet-name><url-pattern>/os</url-pattern></servlet-mapping></web-app>Copy the web.xml under ourwapp\WEB-INF directory.
To deploy the above web application in web logic copy ourwapp.war toC:\bea\user_projects\domains\sunil\applications.In case of Tomcat the war file is copied must underC:\programfiles\Apache Software Foundation\Tomcat\web apps
while starting the web application, web container reads the information available inweb.xml file. Web container can not start the web application, if there is a problem inweb.xml file.Start the server & Open the internet explorer & type the URLhttp://localhost:7001/ourwapp/one.htmlWelcome to one.htmlHere ourwapp is the context path of the web applicationWhen the browser sends the request to one.html (static resource), we (web container)picks of the content of one.html & sends it to the browser as part of the response.http://localhost:7001/ourwapp/osexecutedGET

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->