文章列表
Remember in the original MVC beer app,the Servlet controller talked to the model (Java class with business
logic),the set an attribute in request scope before forwarding to the JSP view.The JSP had to get the attribute
from the request scope,and use it to render a response to send back to the cli ...
Using a PageContext reference to get attributes from any scope,including the page scope for attributes bound to the PageContext.The methods that work with other scopes take an int argument to indicate the scope.Although the attribute access methods come from the JspContext,you'll find the constants f ...
The most of the time you'll be using one of the four implicit objects to get and set attributes corresponding to the four attribute scopes available in a jsp. Remember ,in addition to the standard servlet request,session,application(context) scopes,a JSP adds a fourth scope-----page scope that you ge ...
scriptlet: <% %>
directive: <%@ %>
expression: <%= %>
declaration: <%! %>
The sesssin was created:
when the Container first creates a session,At this point ,the session is still considered new(in other words ,the client has not yet sent a request with the session ID)
the session was destroyed by calling the session's invalidate() method.
Attributes:
an attribute was adde ...
When a Container translates the JSP into a servlet,the beginning of the service method is a pile of implicit object declarations and assignments.
All of the implicit objects map to something from the Servlet/JSP API.The request implicit object ,for example ,is a reference to the HttpServletRequest o ...
Two ways to set session timeout:
1.Configuring session timeout in the DD:
<web-app ..>
<servlet>
...
</servlet>
<session-config>
<session-timeout>15<session-timeout>
</session-config>
</web-app>
2.Setting session timeout for a specific session:
ses ...
getCreationTime() //returns the time the session was first created
getLastAccessedTime() //returns the last time the container got a request with this session ID
setMaxInactiveInterval() //specifies the maximum time,in seconds,that you want to allow between client requests for this session.
getM ...
Put the following code into you java code :
HttpSession session = request.getSession();/*getSession()returns a session no matter what...but you can't tell if it is a new session unless you ask the sesssion.*/
if(session.isNew()){ /*isNew()returns true if the client has not yet responded with this ...
How session work
1.when Diane selects "Dark" and hits the submit button.The Container sends the request to a new thread of the BeerApp servlet.The BeerApp thread finds the session associated with Diane, and stores her choice ("Dark")in the session as an attribute.
2.The servlet ...
We have serveral options:
1.Use a stateful session enterprise javabean.
----Your hosting provider should have a full J2EE server with an EJB Container.
2.Use a database
-----Your hosting provider does allow access to MySQL.You could write the client's data to a database.But this is nearly as much o ...
If the client doesn't accept cookies,we can use URL rewriting as a backup. URL rewriting will always work.URL rewriting takes the session ID that is in the cookie and sticks it right onto the end of every URL that comes in to this app.When the user clicks that "enhanced "link ,the request g ...
HttpSession session = request.getSession(false);<%--Passing "false" means the method returns a pre-existing session or null if there was no session associated with this client.--%>
if(session == null){
session = request.getSession();
}