JSP fourth lesson: Built-in object usage

Source: Internet
Author: User

Related knowledge:

(1) Built-in objects

I. Use of the request

Example 1: Simple login Interface for information

Example 2: Get multi-valued information, such as hobbies

Example 3: Implementing a jump to get object information

Second, to achieve user login

(1) Get login information

(2) Information verification processing

(3) Different pages display login information

Third, the realization of user messages

User message implementation: To implement the user message with the main frame, the display of information also contains the main frame

(1) message.html


<script type= "Text/javascript" >
var s= "1234567";

function changecity () {
Defining arrays
var citylist = new Array ();
citylist[0]=[' Nanjing ', ' Wuxi ', ' Xuzhou ', ' Changzhou ', ' Nantong ', ' Lianyungang ', ' Huaian ', ' Yancheng ', ' Yangzhou ', ' Zhenjiang ', ' Taizhou ', ' Suqian '];
citylist[1]=[' Hangzhou ', ' Ningbo ', ' Wenzhou ', ' jiaxing ', ' Huzhou ', ' Shaoxing ', ' Jinhua ', ' Quzhou ', ' Zhoushan ', ' Taizhou ', ' Yeosu ';
citylist[2]=[' Fuzhou ', ' Xiamen ', ' Putian ', ' sanming ', ' Quanzhou ', ' Zhangzhou ', ' nanping ', ' Longyan ', ' Ningde '];
citylist[3]=[' Changchun ', ' Jilin ', ' siping ', ' Liaoyuan ', ' Tonghua ', ' Bss ', ' Songyuan ', ' Baicheng ', ' Yanbian '];
Gets the index number of the province option, such as Sichuan Province 1, more than the corresponding array index number 1
var pindex=document.myform.selprovince.selectedindex-1;
var NewOption1;
document.myform.selcity.options.length=0;
for (Var j in Citylist[pindex]) {
Newoption1=new Option (Citylist[pindex][j], citylist[pindex][j]);
Document.myform.selCity.options.add (NewOption1);

}
}
function Isemail (Element) {
Return (
Element.value.indexOf ("@")! =-1 &&
Element.value.indexOf (".")! =-1);
}
</script>
<div class= "Fkly" >

<form action= "index.jsp?type=msg" onsubmit= "return check ();" method= "Post" name= "MyForm" class= "Form_css" >< Table width= "100%" border= "0" >
<tr>
&LT;TD width= "20%" > Message title </td>
&LT;TD width= "31%" ><input name= "title" type= "text" id= "title"/></td>
&LT;TD class= "title" Width= "57%" >* must be filled in </td>
</tr>
<tr>
<td> name </td>
<td><input name= "username" type= "text" id= "username"/></td>
&LT;TD class= "username" >* must be filled in, 4-16-bit, content not public </td>
</tr>
<tr>
<td> Sex </td>
<td><input name= "Sex" style= "Border:none; type=" Radio "value=" Man "checked/>
Man
<input name= "Sex" style= "Border:none; type=" Radio "value=" Woman "/>
Women </td>
<td>&nbsp;</td>
</tr>
<tr>
<td> Cities </td>
<td><select name= "selprovince" id= "selprovince" onchange= "changecity ()" >
<option>--Please select the province--</option>
<option value= "Jiangsu province" > Jiangsu Province </option>
<option value= "Zhejiang province" > Zhejiang province </option>
<option value= "Fujian province" > Fujian province </option>
<option value= "Jilin Province" > Jilin Province </option>
</select></td>
<td><select name= "selcity" id= "selcity" >
<option>--Please select City--</option></select></td>
</tr>
<tr>
<td> Contact e-mail </td>
<td><input name= "Email" type= "text" id= "email"/></td>
<td>* must be completed, the content is not public </td>
</tr>
<tr>
<td> Telephone </td>
<td><input name= "Telephone" type= "text" id= "Telephone"/></td>
<td> Web pages will not be published </td>
</tr>
<tr>
<td> Message Content </td>
&LT;TD colspan= "2" ><textarea name= "content" cols= "rows=" 8 ">&nbsp;</textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type= "Submit" class= "BTN1" name= "Submit" value= "Submit"/></td>
<td><input class= "BTN1" type= "reset" name= "reset" value= "reset"/></td>
</tr>
</table>
</form>


(2) Right add information

<%}else if (type.equals ("message")) {%>
<jsp:include page= "message.html" ></jsp:include> fill in the Message information page
<%}else if (type.equals ("MSG")) {%>
<jsp:include page= "msg.jsp" ></jsp:include> Display message Information page

(3) msp.jsp page to achieve the collection of messages, can contain Chinese characters, and display information

Collect message information:

<% @page contenttype= "Text/html;charset=utf-8"%>

<%
Request.setcharacterencoding ("Utf-8");
String title = Request.getparameter ("title");
String username = request.getparameter ("username");
String sex = request.getparameter ("Sex");
String City = request.getparameter ("Selprovince")
+request.getparameter ("selcity");
String email = request.getparameter ("email");
String telephone = request.getparameter ("Telephone");
String content = request.getparameter ("content");
%>

Show Message:

<table width= "100%" border= "0" >
<tbody>
<tr>
&LT;TD width= "20%" > Message title </td>
&LT;TD width= "31%" ><%=title%></td>
</tr>
<tr>
<td> name </td>
<td><%=username%></td>
</tr>
<tr>
<td> Sex </td>
<td><%=sex%></td>
</tr>
<tr>
<td> Cities </td>
<td><%=city%></td>
</tr>
<tr>
<td> Contact e-mail </td>
<td><%=email%></td>
</tr>
<tr>
<td> Telephone </td>
<td><%=telephone%></td>
</tr>
<tr>
<td> Message Content </td>
<td><%=content%></td>
</tr>


</tbody>
</table>

Iv. Use of application

(1) Example: Production Site counter (session, Application Mode)

(2) Application implement small message board

This article is from the "Learn Without thinking" blog, please be sure to keep this source http://dyzyxy.blog.51cto.com/944775/1619060

JSP fourth lesson: Built-in object usage

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.