We will illustrate through the comparison between ASP and JSP syntaxes and objects, the conversion from ASP to JSP can be achieved.
Hidden objects of ASP and JSP
Application Object: Share the current Application information among all users.
- < % Dim ls_write
- For Each Key in Application.Contents
- ls_write = Key + ":"+Application(Key)
- Next
- %>
-
Config Object: stores servlet configuration information, but is rarely used.
Function |
ASP |
JSP |
Object Name |
ASP does not have similar objects |
Config |
Object Type |
N/ |
Javax. servlet. ServletConfig |
Servlet name |
N/ |
GetServletName |
Returns the servlet initialization parameter name. |
N/ |
GetInitParameterNames () |
Obtain the initial parameter value. |
N/ |
GetInitParameter (String name) |
Error Object: any Error information contained in the script
Function |
ASP |
JSP |
Object Name |
ASPError |
Exception |
Object Type |
N/ |
Java. lang. Throwable |
Special note |
In the latest ASP3.0/IIS5.0 object, you can use Server. GetLastError to obtain the ASPError object. |
Only when the page is defined as an error page can it be obtained. You can use the following statement: <% @ Page isErrorPage = "true" %> |
Error Message |
Description () |
GetMessage () |
Get all errors |
ASPDescription () |
ToString () |
Error Tracking |
N/ |
PrintStackTrace (out) |
Error location |
LineColumn |
N/ |
Out: used to write and control the output cache from the server to the browser
Function |
ASP |
JSP |
Object Name |
Response |
Out |
Object Type |
N/ |
Javax. servlet. jsp. JspWriter |
Write Data to the output Cache |
Write variant |
Print (object or primitive data type) |
Write binary data |
BinaryWrite data |
This method must be used through the java OutputStream class. ServletOutputStream Output = response. getOutputStream (); Output. write (Btye [] buffer ); |
Clear out Cache |
Clear |
ClearBuffer () |
Send the current cache to the client |
Flush |
Flush () |
Stop processing the current page |
End |
Close () This is different from end. It closes the current output stream, and the JSP page will still process it. |
Request Object: accept information from the client browser.
Function |
ASP |
JSP |
Object Name |
Request |
Request |
Object Type |
N/ |
Is a subclass of javax. servlet. ServletRequest Usually javax. servlet. HttpServletRequest |
Cookie details |
Cookies [(key). attribute] |
Cookie [] = getCookies () |
Obtain table data |
String = Form (element) [(index)] For example: mydata = Request. Form ("date ") |
String = getParameter (Name) Enum = getParameterNames () string [] = getParameterValues (name) For example: ls_form = request. getParameter ("date "); |
Retrieve query data |
QueryString (element) [(index) |. Count] |
GetParameter (Name) getQueryString () (entire query string) |
HTTP header sent by the client |
ServerVariables (server environment var) For example: ServerVariables (ALL_RAW) returns to you all the headers in raw format |
GetHeaderNames () getHeader (name) getHeaders (name) getIntHeader (name) getDateHeader (name) |
Response Object: send information to the browser. ASP and JSP treat response objects differently. ASP only uses the Response object to control the output to the browser. JSP separates this function into two objects. In JSP, Response is the actual object sent to the client. JSP also uses an out object to write data to the output cache.
Function |
ASP |
JSP |
Object Name |
Response |
Response |
Object Type |
N/ |
It is a subclass of javax. servlet. ServletResponse. It is usually used: javax. servlet. HttpServletResponse |
Cache page output |
Buffer = True/False |
The page cache of JSP is usually 8 K. You can set the cache size. The following example shows how to disable the cache <% @ page buffer = "none" %> |
Enable/disable Proxy Server Cache |
CacheControl = Private/Public |
SetHeader ("Pragma", "no-cache") setHeader ("Cache-Control", "no-cache ") |
Add Cookie |
Cookies [(key). attribute] = value |
AddCookie) |
Add Http Header |
AddHeader Name, Value |
SetHeader (Name, Value) |
Connect the client to another page |
Redirect URL |
SendRedirect (Absolute URL) |
Send error message to client |
N/ |
SendError (int code, String msg) |
Set the output MIME type |
ContentType = "mime type" |
SetContentType ("mime type ") |
Server Object: Provides connections to methods and attributes on the Server.
Function |
ASP |
JSP |
Object Name |
Server |
JSP does not have Server objects. Functions in ASP Server objects have been assigned to other pages. |
Object Type |
N/ |
N/ |
Create an object on the server |
CreateObject (Object id) |
N/ |
Encode a String in HTML format. |
HTMLEncode (String) |
N/ |
Search for files through absolute path |
MapPath (Path) |
N/ |
Encode the URL |
URLEncode (String) |
N/ |
Set timeout |
ScriptTimeout = Seconds |
N/ |
Session Object: share information between multiple pages for a user.
Function |
ASP |
JSP |
Object Name |
Session |
Session |
Object Type |
N/ |
Javax. servlet. http. HttpSession |
Note: |
ASP uses session through cookie |
JSP has two session management methods: 1. Use cookies 2. Use URL rewriting |
Close the session and release its resources |
Abandon |
Invalidate () |
Store a session variable |
Session (String name) = "Your Data" |
SetAttribute (String name, Object object )* |
Store a session Object |
Set Session (String name) = Server. CreateObject (String name) |
Same as above |
Get a session variable |
My_Variable = Session (String name) |
GetAttribute (String name )* |
|
|
|
Obtains a session object. |
Set My_Object = Session (String name) |
Same as above |
Deletes an object or variable of a session. |
Contents. Remove (String name) |
RemoveAttribute (String name) |
Collect content |
Contents |
GetAttributeNames () |
Session ID |
SessionID |
String = getId () |
Set timeout |
Timeout (Minutes) |
SetMaxInactiveInterval (int interval in seconds) |
Get timeout settings |
N/ |
Int = getMaxInactiveInterval () |
Disable session |
<% @ EnableSessionState = False %> |
<% @ Page session = "false" %> |
ASP and JSP scripts
Script Declaration: how to split the server script from the client script.
ASP |
JSP |
<% Your Server Side Script %> |
<% Your Server Side Script %> |
Expression: send data directly to the output cache.
ASP |
JSP |
<% = Your_Variable %> |
<% = Your_Variable %> |
Declaration: declare variables and methods so that they can be used on this page.
ASP |
JSP |
<% Your Function %> |
<%! Your Function %> |
ID: Tell the container how to process this page,
ASP |
JSP |
<% @ Your Directive %> |
<% @ Your Directive %> |
For example, set the script language: <% @ LANGUAGE = "VBSCRIPT" %> Another example is: <% Response. buffer = true %> |
ID to send information to container The identifier does not send messages to the output cache. When the JSP page is initialized, the ID is processed For example, set the script language: <% @ Page language = "java" %> Another example is: <% @ Pagebuffer = "64 k" autoFlush = "true" %> |
Script notes:
Annotation type |
ASP |
JSP |
General Comment |
<% 'Your Comment %> |
Java notes: <% // My comment %> or <%/* my comment */%> |
Specific annotations |
N/ |
JSP comments: <% -- Your comment -- %> This type of annotation is not processed in the container or in the servlet. |
Introduction file of ASP and JSP
Introduction: Before the page is not processed, introduce the file
ASP |
JSP |
<! -- # Include file = "Your File. asp" --> <! -- # Include virtual = "/Your File. asp" --> |
<% @ Include file = "Your File" %> <Jsp: directive. include file = "Your File" %> |
ASP and JSP File Transfer
ASP |
JSP |
Response. redirect ("to_File.asp ") |
Response. sendRedirect ("to_File.asp ") |
- Technical Comparison of ASP and JSP Functions
- How to add a web framework in Servlet
- What are servlets and common Servlet APIs?
- At the beginning of JSP Servlet Development
- Java Servlet API documentation