Jsp Syntax:
Jsp command element
(1) include: import other folders
(2) page:
Language: The language used. It can only be JAVA
ContentType: MIME type
Import: import a java package
(3) taglib: custom tag Library
Common standard elements of jsp
(1) jsp: forward: Jump to other pages
(2) jsp: include: insert other files. For example:
(3) jsp: plugin: insert applet
(4) jsp: param: parameter value passing
Jsp built-in object
(1) request: Common Methods
GetParameter (): extract the value of the form Element
GetRemoteAddr (): obtains the Client IP address.
(2) response:
SendRedirect (): redirects to other web pages
SetcontentType (); sets the MIME Value
(3) out: output to webpage
(4) application
SetAttribute (String, Object) stores the value of the variable in the application;
GetAttribute (String) gets the value stored in applicaion
RemoveAttribute (String) deletes the value stored in the application
(5) session
SetAttribute (String, Object) stores the variable value in the session;
GetAttribute (String) gets the value stored in the session
RemoveAttribute (String) is deleted and saved in
GetID: Get the session number
Jsp Simple Form Processing
<% @ Page contentType = "text/html; charset = gb2312" %>
<% @ Page language = "java" %>
<Html>
<Head> <title> form processing </title>
<Form name = "frm" method = "GET" action = "ch-show.jsp">
<Table boder = 0>
<Tr> <td> User name: </td> <input type = text name = "Tname"> </td> </tr>
<Tr> <td> password: </td> <input type = password name = "Tpass"> </td> </tr>
<Tr> <td> Gender: </td>
<Td> <input type = radio name = "Tsex" value = "male" checked> male
<Input type = radio name = "Tsex" value = "female"> female </td>
</Tr>
<Tr> <td> Hobbies: </td>
<Td> <input type = checkbox name = tsf-value = "Sports"> sports
<Input type = checkbox name = Tch2 value = ""> art
<Input type = checkbox name = Tch3 value = "Music"> music </td>
</Tr>
<Tr> <td> Major: </td> <select name = Ty>
<Option value = "computer"> Computer </option>
<Option value = "Literature"> literature </option>
<Option value = "Mathematics"> mathematics </option>
</Select>
<Tr> <td> message: </td> <textarea name = Tl rows = 5 cols = 20> </textarea> </td> </tr>
<Tr> <td> <input type = submit value = "User Information"> </td> </tr>
</Table> </form>
<%
String Tname = request. getParameter ("Tname ");
String Tpass = request. getParameter ("Tpass ");
String Tsex = request. getParameter ("Tsex ");
String Tlove1 = request. getParameter ("tparameter ");
String Tlove2 = request. getParameter ("Tch2 ");
String Tlove3 = request. getParameter ("Tch3 ");
String Ty = request. getParameter ("Ty ");
String Tl = request. getParameter ("Tl ");
Byte b1 [] = Tsex. getBytes ("ISO-8859-1 ");
Tsex = new String (b1 );
If (Tlove1 = null)
{
Tlove1 = "";
}
Else
{
Byte b2 [] = Tlove1.getBytes ("ISO-8859-1 ");
Tlove1 = new String (b2 );
}
If (Ty = null)
{
Ty = "";
}
Else
{
Byte b5 [] = Ty. getBytes ("ISO-8859-1 ");
Ty = new String (b5 );
}
If (Tlove2 = null)
{
Tlove2 = "";
}
Else
{
Byte b3 [] = Tlove2.getBytes ("ISO-8859-1 ");
Tlove2 = new String (b3 );
}
If (Tlove3 = null)
{
Tlove3 = "";
}
Else
{
Byte b4 [] = Tlove3.getBytes ("ISO-8859-1 ");
Tlove3 = new String (b4 );
}
Out. print ("your information is:" + "<br> ");
Out. print ("username" + Tname + "<br> ");
Out. print ("password" + Tname + "<br> ");
Out. print ("gender" + Tsex + "<br> ");
Out. print ("hobbies" + Tlove1 + Tlove2 + Tlove3 + "<br> ");
Out. print ("professional" + Ty + "<br> ");
Out. print ("message" + Tl + "<br> ");
%>
</Body>