Sunday, October 26, 2008
Saturday, June 28, 2008
what is servlet container!!!!
Now, the question is, we have written a JSP or HTML page to raise a request and Servlet is placed there on server side,having the answer for raised request. Now there would be many servlets as such on the server.
Now who will map our request of that particular servlet and responds back in form of HTTP response.
The answer is : Servlet Container
It acts like a controller.
When container recieves a request for a servlet, through your HTTP GET or HTTP POST method, itcreates a response and request object first.
Then controller searches for the particular servlet requested, as mapped in your web.xml, and creates a thread for the same and assigns those request and response object to it.
Request and Response objects are of HttpServlet class, which your servlet extends.
Container calls the service() method of the servlet.
doGet() or doPost() method generates the dynamic page and attach to it the response object.
When thread completes, the container converts the response object into HTTP response and send it to client.
Followed by deletion of request and response object.
So this is the all story about our servlet CONTAINER.
Friday, June 27, 2008
The ServletContext
Servlet Context, in simple terms, as a shared memory segment for a web application.
when an object has been assigned to this shared memory, will be available to whole web application, until and unless it has been removed.
For every web application, there will be one of ServletContext.
Servlet context is defined in javax.servlet package.
Methods defined in this packages are used at server side to communicate with the servlet container.
They are as follows:
setAttribute()-- binds the object with the specified name, you give, in the current servlet context.
getAttribute()--returns the object assigned by the name provided.
removeAttribute()-- removes the particular object from servlet context.
getAttributeNames()--returns all the objects stored in the current servlet context.
Now, how to get a reference of servlet context,
ServletContext context=getServletContext(); //created context reference object
Now using context object set your object in servletcontext,
String name="JIIT";
context.setAttribute("USER",name);
So,now name object got set in the shared memory of web-application as USER and can be accessible throughout the web-application.
Sunday, June 8, 2008
Why Struts Framework ?
Well, the answer lies in the name "Strut" itself :)
Strut stands for " to provide a structure to impress other".
Four reasons of using Struts, as I think so,
a) easy to learn
b) easy to understand and handle the control flow of your web development
c) widely used, having many forum to discuss out the problem, in case, you face.
d) Many IDEs comes with struts tag.(e.g Jdeveloper)
Sunday, June 1, 2008
What is URL and URI?
Example : http://www.sun.com/
protocol --> http
domain name --> http://www.sun.com/
Here, Domain name(http://www.sun.com/) has been mapped to an IP address (this is the job of Domain Name Server[DNS] to map the entered URL to particular IP address )
URI is basically a part of full URL, it points to specific address.
For Example: http://www.sun.com/aboutsun/index.jsp
So here /aboutsun/index.jsp wil be the URI. Pointing towards the specific address of index.jsp page.
Friday, May 30, 2008
Session Death
- Global default - App Server has its own session timeout depending on the length of the session. Can't do anything with this.
- Webapps default - Here is the time to play with DD file. We can change the web.xml file to define the timeout and here is the small change:

Value here(40) goes in minute in session-timeout tag. But the most important is individual session setting
- Individual session setting: For this, we can write one line servlet code :
HttpSession.setMaxInactiveInterval(2400); // here time is in seconds.
Interesting part is defining 0 or negative in webapps default, leads to a never expired session whereas 0 means Immediate expire and negative means never, in Individual session setting. In HttpSession API, we can always kill the session by calling invalidate() method. So, on log-out button, just call this simple code.
In the next blog, I will try a simple code to see the session life cycle.
Wednesday, May 28, 2008
Error : log4j:WARN Please initialize the log4j system properly
log4j:WARN No appenders could be found for logger(org.apache.struts.util.PropertyMessageResources).
log4j:WARN Please initialize the log4j system properly.
Nothing to worry about, simply add the log4j.jar file in your WEB-INF/lib folder.
At times, your lib folder might be missing in your WEB-INF folder.
Download Log4J.jar file from http://logging.apache.org/log4j/1.2/download.html