Servlets Section Index | Page 42
How can I further optimize my servlets?
You can always wring out some efficiency by
making use of a StringBuffer or ByteArray.
For example, instead of sending your HTML to
the client using a PrintWriter or some other
output stream,...more
What's a better approach for enabling thread-safe servlets and JSPs? SingleThreadModel Interface or Synchronization?
Although the SingleThreadModel technique is easy to use,
and works well for low volume sites, it does not
scale well. If you anticipate your users to increase
in the future, you may be better...more
How does a servlet communicate with a JSP page?
The following code snippet shows how a servlet instantiates a bean and initializes it with
FORM data posted by a browser. The bean is then placed into the request, and the call
is then forwarded ...more
Show me an example of POST request chaining using JSPs and servlets.
[See also http://www.jguru.com/jguru/faq/view.jsp?EID=231318]
The following code example demonstrates how request chaining can be implemented using a
combination of JSPs and servlets.
Consider ...more
How can I implement a thread-safe JSP page?
You can make your JSPs thread-safe by having them implement the
SingleThreadModel interface.
This is done by adding the directive
<%@ page isThreadSafe="false" %>
within your...more
How do I prevent the output of my JSP or Servlet pages from being cached by the browser?
You will need to set the appropriate HTTP header attributes to prevent the
dynamic content output by the JSP page from being cached by the browser.
Just execute the following scriptlet at the beg...more
Are there any ISPs that will host my servlets?
The Adrenaline Group maintains
a list of over 50 ISP's who host Java Servlets (http://www.adrenalinegroup.com/jwsisp.html) . Another list is at http://www.servlets.com.
Those that our gurus (...more
How can I detect whether the user accepted my cookie?
Here's a clever trick: use a redirect. Drop a cookie on the
HttpServletResponse object, then call response.sendRedirect()
to a "phase two" servlet. The "phase two" servlet the...more
How can my applet or application communicate with my servlet?
It's pretty straightforward. You can use the java.net.URLConnection and java.net.URL classes to open a standard HTTP connection to the web server. The server then passes this informa...more
How do I access a database from my servlet or JSP?
[See also How can I pool my database connections so I don't ...]
Since JDK 1.1, Java comes with a package called JDBC (Java Database
Connectivity). JDBC allows you to write SQL queries as Java St...more
How do I create an image (GIF, JPEG, etc.) on the fly from a servlet?
To create an image or do image processing from Java, there are several
packages and classes available. See the Purple Servlet References for a list.
Once you have an image file in your servlet...more
How do I integrate HTML design into my Servlet?
The question can be rephrased, "How can I design a work
flow that incorporates HTML designers and programmers to build a
dynamically generated web site that will keep expanding and
growing ov...more
How do I send email from a servlet?
From:
James Cooper (pixel@bitmechanic.com)
GSP and GnuJSP both come with SMTP classes that make sending email very
simple. if you are writing your own servlet you could grab one of the
many SM...more
How do I upload a file to my servlet or JSP?
On the client side, the client's browser must support form-based
upload. Most modern browsers do, but there's no guarantee. For
example,
<FORM ENCTYPE='multipart/form-data'
method='POST' ...more
What is the difference between URL encoding, URL rewriting, HTML escaping, and entity encoding?
URL Encoding is a process of transforming user input to a CGI form so
it is fit for travel across the network -- basically, stripping
spaces and punctuation and replacing with escape characters. ...more