Unformatted text preview:

Java ServletsWarningAFS ResourcesServlet DefinitionThe Servlet InterfaceSlide 6Slide 7Slide 8Slide 9Servlet MechanicsServlet EnginesServlet AdvantagesSlide 13Comparing Servlets to CGISlide 15Slide 16Java Web ServerHow to Implement ServletsInit MethodService MethodDestroy MethodInitialization ArgumentsInit ExampleHow to Implement Servlets on personal computers and on AFSServlet SetupSlide 26Create a new web applicationUnderstanding the Project FolderCreate a New servlet FileNew Servlet ClassHello.javaHello.java descriptionWeb DescriptionSlide 34Slide 35Running of Hello Servlethttp://localhost:8084/MyFirstServletProject/MyFirstServlet/Congratulations!!!How do you upload this servlet onto AFS?SummaryConnection to Prophet DatabaseConnection to Prophet DatabaseSlide 43Slide 44Slide 45Slide 46Slide 47Slide 48Basic rules to connect to JDBCCode to connect JDBC to AFSGeneral tips to connect to JDBCTips for effective resultsExample code to add recordServlet SecurityServlet Sand BoxAnalogy: A child’s sandboxServlet Sand Box (2)Access Control Lists (ACL)ACL SpecificationThreading with ServletsServlet methodsUnsafe Servlet example (1)Unsafe Servlet example (2)Safe Servlet example (1)Safe Servlet example (2)ConclusionHints for Servlets on AFSJava ServletsRamaKrishna Dantuluri,Ranjini Nair, Kalpesh Patel,Chandra Mouli GudaWarning•If you are implementing servlets using Tomcat on AFS you will have to wait until the server is restarted before your code can be tested. •It will not work until the server is restarted at 6 a.m., 2 p.m., and 8 p.m. daily. It takes about half an hour to restart each time as Tomcat has to check about 5,000 home directories for JSP and servlets. See the last slide in this lecture for more information on using Tomcat on AFS.AFS Resources•See the left hand menu at http://web.njit.edu/ especially http://web.njit.edu/all_topics/Servers/Tomcat/ •To use Tomcat on AFS, go to your public_html directory and run the script tomcat.setup. This will install Tomcat and also give you working demos of both JSP and servlets. The demos are running on the professor’s Web site at the bottom of this page: •http://web.njit.edu/~gblank/cis602/StealThis.html •The demos listed above can also be used to test Tomcat on AFS. If they work, the problem is in your code, not AFS!Servlet Definition•Servlets are protocol- and platform-independent server side components, written in Java, which dynamically extend Java-enabled servers.•They have become more and more popular as they benefit from all the advantages of the Java programming language in particular Architecture and Platform Independence and the ability to build robust and secure applications.The Servlet Interface•A Servlet, in its most general form, is an instance of a class, which implements the javax.servlet.Servlet interface. •Most Servlets, extend one of the standard implementations of that interface, usually javax.servlet.http.HttpServlet. •HTTP Servlets extend the javax.servlet.http.HttpServlet class.Servlet Definition•Servlets are to a server what applets are to client browsers. Because Servlets run within the server there is no graphical user interface. Communication with a Servlet occurs through the Server API, which although not part of the core Java framework is supported my many manufacturers as an add-on.Servlet Definition•A Servlet, in simple terms, is a Java program running under a web server taking a 'request' object as an input and responding back by a 'response' object. Typically a web browser will send the request in HTTP format. The Servlet container will convert that into a request object. Similarly the response object - populated by the Servlet is converted into an HTTP response by the Servlet container.Servlet Definition•This mechanism makes the browser - web server interaction very easy. Java Servlets are more efficient, easier to use, more powerful, more portable, and cheaper than traditional CGI and many alternative CGI-like technologies. •(More importantly, Servlet developers tend to get paid more than Perl programmers :-).Servlet Definition•Java Server Pages (JSP) is a technology that lets you mix regular, static HTML with dynamically-generated HTML. Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations.•But most CGI variations, including Servlets, make you generate the entire page via your program, even though most of it is always the same.Servlet Mechanics•A servlet is a Java class and thus needs to be executed in a Java Virtual Machine by a service called a servlet engine. The servlet engine loads the servlet before it can be used. The servlet then stays loaded until it is unloaded or the servlet engine is shut down.Servlet Engines•Some web servers, including Sun Java Web Server, W3C Jigsaw, and Gefion LiteWebServer are implemented in Java and have a built in servlet engine. High end commercial servers like Websphere and Web Logic tend to include a servlet engine. Other web servers such as Microsoft IIS and Apache require a servlet add-on module which must be loaded separately.Servlet AdvantagesRamaKrishna DantuluriServlet Advantages•Possibly the biggest advantage of Java Servlets is that they run within the context of the server. This along with the multithreading characteristic of Java means that the server doesn’t have to begin a new process for every request made. Instead, the server creates a single instance of the Servlet, which handles all client requests, thus allowing Servlets to out perform both the CGI approach and the Fast-CGI approach.Comparing Servlets to CGI•Servlets are more efficient. With traditional CGI, a new process is started for each HTTP request. If the CGI program does a relatively fast operation, the overhead of starting the process can dominate the execution time. •With servlets, the Java Virtual Machine stays up, and each request is handled by a lightweight Java thread, not a heavyweight operating system process.Comparing Servlets to CGI•Servlets also have more alternatives than do regular CGI programs for optimizations, such as caching previous computations and keeping database connections open.•Servlets are more convenient. Servlets have an extensive infrastructure for automatically parsing and decoding HTML form data, reading and setting HTTP headers, handling cookies, tracking sessions, and many other such tasks.Comparing Servlets to CGI•Java Servlets can do


View Full Document

NJIT CS 602 - Java Servlets

Download Java Servlets
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Java Servlets and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Java Servlets 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?