JSP database Interaction Object

Source: Internet
Author: User
Tags object object response code

Jspthe built-in object is in writingJSPObject that can be used directly without any claims

Common built-in objects

Out,request,response, session,application

the Out object is used to output data to the browser

The request object obtains relevant data from requests and browser-related information, which fails at the end of a page jump or request

common methods for Request objects:

String Getrequestparameter (string name) Gets the page submission data based on the name in the page form

String Getrequestparametervalues (string name) gets a set of form components with the same name to submit data

Void setcharacterencoding (String character) Specifies the encoding of the request

Requsetdispatcher getrequsetdispatcher (String path) for forwarding requests

The Response object is used to set the response parameters and get the response flow, etc.

Void Addcookie (Cookie cookie) adds a cookie to the client

Void setcontenttype (String type) sets the contentType type of HTTP

Void setcharacterencoding (String type) sets the type of character encoding taken by the response

Void Sendredirect (String location) to relocate the request to a new URL

What is the difference between forwarding and redirection?

Difference 1:

URL changes on the browser when redirected
Forwarding is the same as the URL on the browser
Difference 2:
Redirect actually produces two requests
Forward only one request
Redirect:
send a request --The server runs a response request, returns a new address and response code to the browser, and the browser responds to the response code, determines that the response is redirected, automatically sends a new request to the server, and the request address is the address that was returned before-- The server runs and responds to requests to the browser
Forward:
send a request --The server runs--make the requested reset, for example via Request.setattribute (Name,value)--based on the forwarded address, get the address of the page-- Responding to a request to a browser
Difference 3:
The URL of the redirect can be any URL
The URL to be forwarded must be the URL of this site

Session Object A conversation is a series of related interactions between a user and a Web server over a period of time. It can contain multiple requests between the browser and the server. Response process.

Common methods for session objects

String getId () gets the ID

Void setmaxinactiveinterval (int interval) Set session inactivity time

Int Getmaxinactiveinterval () Gets the session active inactivity time (in seconds)

void invalidate () Setting session object invalidation

Void SetAttribute (String Key,object object) saved to the session object with key-value pairs

Object GetAttribute (String key) Gets the objects in session by key

Void removeattribute (String key) removes the specified key corresponding object from the Session object

Expiration of Session

one is the session timeout the other is to manually call the method setting to fail

1. Setmaxinactiveinterval () setting through the session object

<%

Seesion.setattribute ("admin", "admin");

Session.setmaxinactiveinterval (600);

Response.sendredirect ("admin.jsp");

%>

2. Set up the code in the Project Web. xml

<session-config>

<session-timeout>10</session-timeout>

</session-config>

3. in the application server settings, locate the <session-config> element in the Tomcat directory/conf/web.xml, where 30 of the <session-timeout> element is the default time, Unit minutes.

The include directive indicates that inserting a text or code file during JSP compilation is static

syntax <% @include file= "application file path

JSP database Interaction Object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.