servlets

is there any wayout to set init parameter in servletconfig or servletContext object?

if i want to modify init-parameter value in any of ServletContext or ServletConfig. any want it to be updated after servlet is destroyed by container. is there any wayout? ...

Creating website

Hi, I want to create a website over banking. I just wanna know what's more do I have to know to create website. Is the knowledge of servlet, JSP, HTML, CSS is enough to make a website? Or do I have to know Javascript as well? Thanks in advance. ...

Mapping--definition problem

Hi, could anyone please tell me the meaning of the word mapping in the following line: When you define a servlet for a JSP, you must also define mapping to the JSP page. Thanks in advance. ...

java servlet:response.sendRedirect() not giving illegal state exception if called after commit of response.why?

after commit of response as here redirect statement should give exception but it is not doing so if this redirect statemnet is in if block.but it does give exception in case it is out of if block.i have shown same statement(with marked stars ) at two places below.can u please tell me reason for it. protected void doPost(HttpServletR...

How can I use the J2EE Timer Service API in the Servlet startup code?

For a background job which I would like to run in a J2EE container, I found the suggestion to create a startup servlet and use the Timer Service API to create a managed Timer (in the answers for What tools are there for timed batch processes in J2EE?). To create a timer, I need a context which implements the timer API. (Example) In th...

Standard action

Hi, I really don't understand why the following code in JSP is running fine, but as described in Head first book, it will show compile time error. <html><body> <jsp:useBean id="person" type="foo.Person" scope="request"> <jsp:setProperty name="person" property="name" value="Fred"/> </jsp:useBean> <jsp:getProperty name="person" prope...

Browser caching

Hi, I am developing a web site which uses lot of images.I would like to make all images are to be stored in browser's cache till some specified time.Now it is stored in browser's cache.However if we refresh the page in browser it is making request to server for particular resource.Server responds with 304 code(NOT MODIFIED).I want to av...

In servlet destroy() is called first or finalize()?

Hi In a servlet, is destroy() called before or after finalize()? ...

How to redirect to Login page when Session is expired in Java web application?

I'm running a web application in JBoss AS 5. I also have a servlet filter which intercepts all the requests to the server. Now, I want to redirect the users to the login page, if the session has expired. I need to do this 'isSessionExpired()' check in the filter and need to redirect the user accordingly. How do I do it? Edit: I'm setti...

Using Servlets and JSP together resulting in unexpected looping.

I'm trying to use Servlets as a controller layer and JSPs as a view layer. Many of the examples/tutorials I've read suggest doing somehting like this: public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // add something for the JSP to work on request.setAttribute("key", "v...

How can I map a "root" Servlet so that other scripts are still runnable?

I'm trying to build a Servlet that calls a JSP page similar to the following: public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { req.getRequestDispatcher("/WEB-INF/main.jsp").forward(req, resp); } I need this Servlet to respond to the domain's root (eg: http://example.com/) so...

Is it advisable to cast HttpSession as ClientSession in Java? What is the best practice?

The question is self explanatory I guess. This is what I am doing: Student student = Student.findStudent(s.getRegNumber(), (ClientSession)httpSesn); findStudent() method returns me an object of the Student class. As you can see I am casting HttpSession object into a ClientSession. Is it advisable? Are their any hidden snags involved? ...

How do you detect the URL in a Java Servlet when forwarding to JSP?

I have a servlet that looks something like this: public class ExampleServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.getWriter().println(request.getPathInfo()); } } with a web.xml mapping like: <servlet> <servlet-name>exampl...

What libraries are there for processing XML on Google App Engine/Java Servlet

I'm writing a Java servlet in Eclipse (to be hosted on Google App Engine) and need to process an XML document. What libraries are available that are easy to add to an Eclipse project and have good example code? ...

Java Servlet API 2.5 Cookie.getDomain() always returns null

I'm having an issue using the Cookie class of the Servlet API 2.5 on Tomcat . I pull out the list of cookies from the HttpServletRequest object and iterate over them like so: Cookie[] cookies = request.getCookies(); for(Cookie cookie : cookies) { System.out.println("Name=" + cookie.getName() + " Domain=" + cookie.getDomain()); } Ho...

How to save data upon http session invalidation through jsp / servlets?

To track user activity history on a web application, I am attempting to save some session data to a database when the session is invalidated. My initial approach was to store the data on a javabean with a session scope and have it dump its data to the database through the finalize method. I figured this wouldn't be a perfect solution du...

My class is not a servlet error

I have the following servlet code public void doPost(HttpServletRequest request, HttpServletResponse response){ Backup bup = new Backup(); bup.doBackup(); response.setContentType("text/html"); PrintWriter out; try { out = response.getWriter(); out.println("You backed up your data - well hopefully"); out.flush(); out.close()...

Tuning Tomcat memory and cpu consumption

Hello all. I have a Java web application that works a lot with file conventions. I am using Tomcat 6 as my servlet container. When many requests are submitted, Tomcat becomes very memory hungry. I wonder how I can fine-tune tomcat to reduce the memory consumption. I am also considering changing my servlet container. What do you suggest? ...

enabling el in jsp

Hi, could anyone tell me how can I enable EL expression in JSP version 2.0? Every time I'm getting EL expression as an String literal in the JSP as an output. Here's the DD which the container is using to sending request to servlet, and then servlet dispating request to JSP: <web-app xmlns="http://java.sun.com/xml/ns/j2ee" ...

Servlet service XSLTC transforming error

Following what seem to be the standard way to perform transformations using translets; see http://xml.apache.org/xalan-j/xsltc_usage.html#api; We perform the following steps Set the javax.xml.transform.TransformerFactory system property as indicated... Instantiate a TransformerFactory. Instantiate a Transformer object either directly...