Advanced Features Complete HelloWorldServlet Example
4.5 Advanced Features
The preceding steps create a basic servlet. You will probably also use more advanced features of servlets: ■ Handling HTML form data—HTTP servlets can receive and process data received from a browser client in HTML forms. – Section 9.3, Retrieving Client Input ■ Application design—HTTP servlets offer many ways to design your application. The following sections provide detailed information about writing servlets: – Section 9.2, Providing an HTTP Response – Section 9.9, Threading Issues in HTTP Servlets – Section 9.10, Dispatching Requests to Another Resource ■ Initializing a servlet—if your servlet needs to initialize data, accept initialization arguments, or perform other actions when the servlet is initialized, you can override the init method. – Section 9.1, Initializing a Servlet ■ Use of sessions and persistence in your servlet—sessions and persistence allow you to track your users within and between HTTP sessions. Session management includes the use of cookies. For more information, see the following sections: – Section 10.6, Session Tracking from a Servlet – Section 9.5, Using Cookies in a Servlet – Section 10.3, Configuring Session Persistence ■ Use of WebLogic services in your servlet—WebLogic Server provides a variety of services and APIs that you can use in your Web applications. These services include Java Database Connectivity JDBC drivers, JDBC database connection pools, Java Messaging Service JMS, Enterprise JavaBeans EJB, and Remote Method Invocation RMI. For more information, see the following sections: – Section 9.7, Using WebLogic Services from an HTTP Servlet – Section 9.8, Accessing Databases Creating and Configuring Servlets 4-74.6 Complete HelloWorldServlet Example
This section provides the complete Java source code for the example used in the preceding procedure. The example is a simple servlet that provides a response to an HTTP request. Later in this document, this example is expanded to illustrate how to use HTTP parameters, cookies, and session tracking. Example 4–3 HelloWorldServlet.java import javax.servlet.; import javax.servlet.http.; import java.io.; public class HelloWorldServlet extends HttpServlet { public void serviceHttpServletRequest req, HttpServletResponse res throws IOException { Must set the content type first res.setContentTypetexthtml; Now obtain a PrintWriter to insert HTML into PrintWriter out = res.getWriter; out.printlnhtmlheadtitle + Hello Worldtitlehead; out.printlnbodyh1Hello Worldh1bodyhtml; } } You can find the source code and instructions for compiling and running examples in the samplesexamplesservlets directory of your WebLogic Server distribution.4.7 Debugging Servlet Containers
Parts
» Oracle Fusion Middleware Online Documentation Library
» Document Scope and Audience Guide To This Document
» Servlets and Java EE What You Can Do with Servlets
» JSPs and Java EE What You Can Do with JSPs Overview of How JSP Requests Are Handled
» Related Documentation New and Changed Features In This Release Web Application Security
» Avoiding Session Fixation Attacks in Programmatic Login Avoiding Redirection Attacks
» Step One: Create the Enterprise Application Wrapper Step Two: Create the Web Application
» Servlet Mapping Configuring Servlets
» Setting Up a Default Servlet Servlet Initialization Attributes
» Writing a Simple HTTP Servlet
» Advanced Features Complete HelloWorldServlet Example
» Usage Tracking a Request Handle Footprint
» WebLogic JSP and Java EE Configuring Java Server Pages JSPs Registering a JSP as a Servlet
» Configuring JSP Tag Libraries Configuring Welcome Files
» Customizing HTTP Error Responses Determining the Encoding of an HTTP Request
» JavaServer Faces JSF JavaServer Pages Standard Tag Libraries JSTL
» Referencing External EJBs More about the ejb-ref Elements
» Referencing Application-Scoped EJBs Oracle Fusion Middleware Online Documentation Library
» Configuring WebLogic Server to Use CGI
» Web Component Classes That Support Annotations
» Initializing a Servlet when WebLogic Server Starts Overriding the init Method
» Serving Resources from the CLASSPATH with the ClasspathServlet Providing an HTTP Response
» Methods for Using the HTTP Request Example: Retrieving Input by Using Query Parameters
» Setting Cookies in an HTTP Servlet Retrieving Cookies in an HTTP Servlet
» Forwarding a Request Including a Request
» Setting Up a Proxy to a Secondary Web Server
» Sample Deployment Descriptor for the Proxy Servlet
» Using WebLogic Services from an HTTP Servlet Threading Issues in HTTP Servlets Clustering Servlets
» Referencing a Servlet in a Web Application URL Pattern Matching
» doRequest doResponse doTimeOut Abstract Asynchronous Servlet
» Future Response Servlet A Future Response Model for HTTP Servlets
» HTTP Session Properties Session Timeout Configuring WebLogic Server Session Cookies
» Configuring Application Cookies That Outlive a Session Logging Out
» Configuring JDBC-based Persistent Storage
» Caching and Database Updates for JDBC Session Persistence Using Cookie-Based Session Persistence
» Coding Guidelines for URL Rewriting URL Rewriting and Wireless Access Protocol WAP
» A History of Session Tracking Tracking a Session with an HttpSession Object
» Lifetime of a Session How Session Tracking Works
» Detecting the Start of a Session Setting and Getting Session NameValue Attributes
» Configuring Session Tracking Using URL Rewriting Instead of Cookies
» Scenarios to Avoid When Using Sessions Use Serializable Attribute Values
» How the Pub-Sub Server Works
» Channels Message Delivery and Order of Delivery Guarantee
» Creating the weblogic-pubsub.xml File
» Overview of the Main API Classes and Interfaces
» Getting a Pub-Sub Server Instance and Creating a Local Client Publishing Messages to a Channel
» Programming the Message Filter Class Configuring the Message Filter Chain
» Updating a Browser Client to Communicate with the Pub-Sub Server
» Overriding the Default Servlet Mapping of the pubsub Java EE Library
» Specify Access to Channel Operations Restricting Access to All Channel Operations
» Map Roles to Principals Configure SSL for Pub-Sub Communication
» Use AuthCookieEnabled to Access Resources Locking Down the Pub-Sub Server
» Configuring JMS as a Handler
» Configuring Persistent Channels Advanced Topic: Persisting Messages to Physical Storage
» Declarations Scriptlets Oracle Fusion Middleware Online Documentation Library
» Expressions Example of a JSP with HTML and Embedded Java
» Instantiating the JavaBean Object Doing Setup Work at JavaBean Instantiation
» Forwarding Requests Including Requests
» Expressions and Attribute Values
» JSP Expression Language Implicit Objects
» Literals Errors, Warnings, Default Values Operators Operator Precedence
» JSP Compiler Syntax JSP Compiler Options
» Using the JSPClassServlet Precompiling JSPs
» Configuring a Filter Configuring Filters
» Writing a Filter Class Filtering the Servlet Response Object Additional Resources
» Overview of WebLogic JSP Form Validation Tags Using WebLogic JSP Form Validation Tags in a JSP
» Sample JSP with Validator Tags
» Refreshing a Cache Flushing a Cache
» Repeat Tag Overview of the WebLogic EJB-to-JSP Integration Tool
» Basic Operation Interface Source Files
» Build Options Panel Troubleshooting
Show more