BEA Home | Events | Solutions | Partners | Products | Services | Download | Developer Center | WebSUPPORT
| WebLogic Server Doc Home | FAQ | Previous Topic | Next Topic | Contents | View as PDF

FAQs: Server-Side Java (Servlets)

- How do I call a servlet with parameters in the URL?

- How can I run multiple instances of the same servlet class in the same WebLogic Server instance?

- How do I deserialize an httpsession?

How do I call a servlet with parameters in the URL?

The usual format of a servlet parameter is a name=value pair that comes after a question-mark (?) at the end of the URL. To access these parameters, call the getParameter() method on the HttpServletRequest object, then write code to test the strings. For example, if your URL parameters are "func=topic," where your URL appears as:

>       http://www.myserver.com/myservlet?func=topic

then you could parse the parameter as follows, where "req" is the HttpServletRequest object:

>       String func = req.getParameter("func");
>       if (func.equalsIgnoreCase("topic")) {
>         . . . do some work
>       }

How can I run multiple instances of the same servlet class in the same WebLogic Server instance?

If you want to run multiple instances, your servlet will have to implement the SingleThreadModel interface. An instance of a class that implements the SingleThreadModel interface is guaranteed not to be invoked by multiple threads simultaneously. Multiple instances of a SingleThreadModel interface are used to service simultaneous requests, each running in a single thread.

When designing your servlet, consider how you use shared resources outside of the servlet class such as file and database access. Because there are multiple instances of servlets that are identical, and may use exactly the same resources, there are still synchronization and sharing issues that must be resolved, even if you do implement the SingleThreadModel interface.

How do I deserialize an httpsession?

To deserialize an httpsession, construct a utility class that uses the current thread's contextclassloader to load the user defined objects within the application context. then add this utility class to the system CLASSPATH.

Copyright © 2001 BEA Systems, Inc. All rights reserved. Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.