Servlets Section Index | Page 6
What's the initial user name and password for Jakarta Tomcat 4's admin tool?
As far as I know, there is no user that is assigned the 'admin' role after an installation of tomcat. (For security reasons I assume).
You can assign this role to a username/password combination o...more
How can I unit test my servlets?
You may want to look into HttpUnit for doing unit testing, esp. the ServletUnit section. It's integrated with JUnit and allows you to do programmatic testing of servlets in-process or remotely -- ...more
How to close database connection explicitly when session is ended?
You need to be notified by the web server when the session expires. To do that you need to implement the HttpSessionListener (Servlet 2.3 spec) interface and configure it in the deployment descrip...more
How to get url of current request from HttpServletRequest? for example "http://site/index.jsp?id=1"
Try
String getFullURL(HttpRequest request) {
StringBuffer url = request.getRequestURL();
if (request.getQueryString() != null) {
url.append('?');
url.append(request.getQueryString());
}
r...more
Using JSP I can use implicit object exception when my JSP page is declared with <%@ page isErrorPage="true" %> directive. But how to get this reference programmatically, for example with a servlet ?
It is possible to get a reference to the exception even if our page is not declared with isErrorPage="true" attribute, or inside a servlet.
The Java Servlet Specification
Version 2.3 / JSP 1.2 (pa...more
Why do I get the error. org.xml.sax.SAXParseException : Element type "web-app" must be declared. when starting my web application? It has a web-app element already!
Why do I get the error
org.xml.sax.SAXParseException : Element type "web-app" must be declared
when starting my web application? It has a web-app element already!
How can I prevent the expiration of a Session?
Hi,
You can change the "timeout" value in two ways.
To change one or more session (but on a per-session basis), use the setMaxInactiveInterval(int interval) method of the javax.servlet.http.HttpSe...more
Since session.getValue("name") has been deprecated, what method do I call instead?
Use session.getAttribute("name").toString() to accomplish the same thing as the deprecated getValue method.
What is the difference between request.getAttribute() and request.getParameter()?
In a request object you can store, on the server side, some object that can be useful during the processing of your pages. This uses request.setAttribute() and request.getAttribute().
Remember t...more
How can I access one servlet method from some other servlet in same context?
You do not call methods on the servlet from other servlets. If you need to perform some functionality in many servlets, put that functionality in some other object that you can create from both se...more
How can I store international / Unicode characters into a cookie?
Example:
I would like to put this String: "até" The problem is when I get the cookie value I receive "at".
----------------------
One way is that before storing the cookie URLEncode it.
...more
How do I pass some servlet variable to javascript?
How do I pass some servlet variable to javascript?
How to check for the validation of a Unix login username and password from Java?
See http://cscene.org/CS4/CS4-04.html for a JNI tutorial with source code which verifies a user's password.
I read the section on Filters and the spec seems to be silent on some issues… Can you clarify?
1. Can a filter attach new objects to the request without having to create a request wrapper. I have no need to override any methods in request just make available some objects downstream to othe...more
Our servlet program needs to read an image file (*.jpg or gif) and create thumnail files. Is there any program available I can use ?
Try these links:http://java.sun.com/products/jimi/
http://rsb.info.nih.gov/ij/
Java Advanced Imaging
You'll find how to read and write some image formats. How to apply some effects. And if I reme...more