JSP syntax:
JSP directive elements
(1) Include: Import other folders
(2) Page:
Language: In what language, only Java
Contenttype:mime type
Import: Importing Java Packages
(3) Taglib: Custom Tag Library
JSP Common standard elements
(1) Jsp:forward: Jump to other pages
(2) Jsp:include: Insert other documents eg:
(3) Jsp:plugin: Insert Applet Small Program
(4) Jsp:param: Parameter Transfer value
JSP built-in objects
(1) Request: Common methods
GetParameter (): Extracts the value of a FORM element
GETREMOTEADDR (): Getting Client IP values
(2) Response:
Sendredirect (): Redirect to another page
setContentType (); Set MIME value
(3) Out: Output to the Web page
(4) Application
SetAttribute (string,object) holds the value of the variable in application;
GetAttribute (String) to get the value saved in Applicaion
RemoveAttribute (String) to delete values saved in application
(5) session
SetAttribute (String,object) Saves the value of the variable in session;
GetAttribute (String) to get values saved in session
RemoveAttribute (String) deletion is saved in the
GetID: Get Session number
JSP simple Form processing
<% @page contenttype= "text/html;charset=gb2312"%>
<% @page language= "java"%>
<form name= "frm" method= "get" action= "ch-show.jsp" >
<table boder=0>
<tr><td> User name: </td><td><input type=text name= "Tname" ></td></tr>
<tr><td> Password: </td><td><input type=password name= "Tpass" ></td></tr>
<tr><td> Sex:</td>
<td><input type=radio name= "tsex" value= "male" checked> male
<input type=radio name= "Tsex" value= "female" > </td>
</tr>
<tr><td> Hobby:</td>
<td><input type=checkbox name=tch1 value= "Sports" > Sports
<input type=checkbox name=tch2 value= "Fine Art" > Art
<input type=checkbox Name=tch3 value= "Music" > Music </td>
</tr>
<tr><td> Major: </td><td><select name=ty>
<option value= "Computer" > Computer </option>
<option value= "Literature" > Literature </option>
<option value= "Mathematics" > Mathematics </option>
</select>
<tr><td> message: </td><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 ("Tch1");
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 message is:" + "<br>");
Out.print ("User name" +tname+ "<br>");
Out.print ("Password" +tname+ "<br>");
Out.print ("Gender" +tsex+ "<br>");
Out.print ("Hobby" +tlove1+tlove2+tlove3+ "<br>");
Out.print ("Professional" +ty+ "<br>");
Out.print ("message" +tl+ "<br>");
%>
</body>