?? sessionuserlogin.jsp
字號:
<%@ page contentType="text/html;charset=gb2312"%>
<script language="javascript">
function on_submit()
{//驗證數據的合法性
if (form1.username.value == "")
{
alert("用戶名不能為空,請輸入用戶名!");
form1.username.focus();
return false;
}
if (form1.userpassword.value == "")
{
alert("用戶密碼不能為空,請輸入密碼!");
form1.userpassword.focus();
return false;
}
}
</script>
<%!
public String codeToString(String str)
{//處理中文字符串的函數
String s=str;
try
{
byte tempB[]=s.getBytes("ISO-8859-1");
s=new String(tempB);
return s;
}
catch(Exception e)
{
return s;
}
}
%>
<%
String username=request.getParameter("username");
String userpassword=request.getParameter("userpassword");
if(username!=null&userpassword!=null)
{//如果用戶名和密碼都合法,記下用戶名,一般把用戶和密碼存在數據庫中,
//用數據庫中的信息與提交的用戶名和密碼比較以進行用戶合法性檢查,
//這些內容在后續章節中會繼續學習
session.setAttribute("username",codeToString(username));
response.sendRedirect("sessionUserLogin1.jsp");
}
%>
<html>
<head>
<title>用戶登錄</title>
</head>
<body>
<table aligin="center">
<form name="form1" method="post" action="sessionUserLogin.jsp" onsubmit="return on_submit()">
<tr aligin="center">
<td>
用戶登錄
</td>
</tr>
<tr aligin="center">
<td>
請輸入用戶名:<input type="text" name="username" size="20">
</td>
</tr>
<tr aligin="center">
<td>
請輸入密碼: <input type="password" name="userpassword" size="20">
</td>
</tr>
<tr aligin="center">
<td>
<input type="submit" value="提交" name="B1">
<input type="reset" value="全部重寫" name="B2">
</td>
</tr>
</form>
</table>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -