response.sendRedirect("你要跳转的页面.jsp?usename="+usename)
//在你要跳转的页面,就用request获取就行了。
<h1><%=request.getParameter("usename")%>!欢迎你的登陆!</h1>
具体的话,应该是这么写,其实也还有其他的方法,我就只记得这一个了,希望能帮到你
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%><%
String path = request.getContextPath()
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>注册啦..</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link href="../css/rayx.css" type="text/css" rel="stylesheet">
<title>填写注册信息</title>
<script language="javascript">
<!--
function selectCity(){
if(RegInfoPost.state.value=="上海"){
RegInfoPost.city.value="上海"
}
else if(RegInfoPost.state.value=="天津"){
RegInfoPost.city.value="天津"
}
else if(RegInfoPost.state.value=="北京"){
RegInfoPost.city.value="北京"
}
else if(RegInfoPost.state.value=="重庆"){
RegInfoPost.city.value="重庆"
}
else if(RegInfoPost.state.value=="中国香港"){
RegInfoPost.city.value="中国香港"
}
else if(RegInfoPost.state.value=="中国澳门"){
RegInfoPost.city.value="中国澳门"
}
else{
RegInfoPost.city.value=""
}
}
function checkCity(){
if(RegInfoPost.city.value=="北京"){
RegInfoPost.address.focus()
}
if(RegInfoPost.city.value=="上海"){
RegInfoPost.address.focus()
}
if(RegInfoPost.city.value=="天津"){
RegInfoPost.address.focus()
}
if(RegInfoPost.city.value=="重庆"){
RegInfoPost.address.focus()
}
if(RegInfoPost.city.value=="中国香港"){
RegInfoPost.address.focus()
}
if(RegInfoPost.city.value=="中国澳门"){
RegInfoPost.address.focus()
}
}
-->
</script>
<script language="javascript">
<!--
function onSubmit(){
<%//检查姓名%>
if(RegInfoPost.realName.value==""){
alert("请填写姓名!")
RegInfoPost.realName.focus()
return false
}
<%//检查身份z%>
else if(RegInfoPost.identityCard.value==""){
alert("请填写身份z号码!")
RegInfoPost.identityCard.focus()
return false
}
<%//检查身份z的格式是否合法%>
else if(chkid(RegInfoPost.identityCard.value)==0){
alert("您填写的身份z号码不是合法的身份z号码!")
RegInfoPost.identityCard.focus()
return false
}
<%//检查邮政编码%>
else if(RegInfoPost.zip.value==""){
alert("请填写邮政编码!")
RegInfoPost.zip.focus()
return false
}
<%//检查邮政编码是否含有空格%>
else if(chkspc(RegInfoPost.zip.value)!=1){
alert("邮政编码含有空格!")
RegInfoPost.zip.focus()
return false
}
<%//检查邮政编码是否符合格式%>
else if(checkZip(RegInfoPost.zip.value)==0){
alert("不是中国的邮政编码,或者邮政编码有非法字符!")
RegInfoPost.zip.focus()
return false
}
<%//检查省市自治区%>
else if(RegInfoPost.state.value=="default"){
alert("请选择省市自治区!")
RegInfoPost.state.focus()
return false
}
<%//检查城市%>
else if(RegInfoPost.city.value==""){
alert("请填写城市!")
RegInfoPost.city.focus()
return false
}
<%//检查地址%>
else if(RegInfoPost.address.value==""){
alert("请填写地址!")
RegInfoPost.address.focus()
return false
}
<%//检查主要联系电话%>
else if(RegInfoPost.phone.value==""){
alert("请填写主要联系电话!")
RegInfoPost.phone.focus()
return false
}
<%//检查生日(年)%>
else if(RegInfoPost.birthdayYear.value==""){
alert("请填写您的生日!")
RegInfoPost.birthdayYear.focus()
return false
}
<%//检查出生年份有效性%>
else if(chkYear(RegInfoPost.birthdayYear.value)==0){
alert("您的生日不符合格式!")
RegInfoPost.birthdayYear.focus()
return false
}
<%//检查生日(月)%>
else if(RegInfoPost.birthdayMonth.value=="default"){
alert("请填写您的生日!")
RegInfoPost.birthdayMonth.focus()
return false
}
<%//检查生日(日)%>
else if(RegInfoPost.birthdayDay.value=="default"){
alert("请填写您的生日!")
RegInfoPost.birthdayDay.focus()
return false
}
<%//检查电子邮件%>
else if(RegInfoPost.email.value==""){
alert("请填写您的电子邮件地址!")
RegInfoPost.email.focus()
return false
}
<%//检查电子邮件是否合法%>
else if(chkemail(RegInfoPost.email.value)!=1){
alert("电子邮件地址不符合格式!")
RegInfoPost.email.focus()
return false
}
<%//检查用于确认的电子邮件地址%>
else if(RegInfoPost.email.value!=RegInfoPost.email2.value){
alert("请确认您的电子邮件填写的准确无误!")
RegInfoPost.email2.focus()
return false
}
else{
<%
session.setAttribute("frompage","reg.jsp")
%>
RegInfoPost.submit()
}
}
<%
//函数名:chkspc
//功能介绍:检查是否含有空格
//参数说明:要检查的字符串
//返回值:0:有空格 1:没有空格 2:有空格
%>
function chkspc(a){
var i=a.length
var j = 0
var k = 0
while(k<i){
if(a.charAt(k)!=" "){
j = j+1
}
k = k+1
}
if(j==0){
return 0
}
if(i!=j){
return 2
}
else{
return 1
}
}
<%
//函数名:checkNum
//功能介绍:检查是否为数字
//参数说明:要检查的数字
//返回值:0:不是数字 1:是数字
%>
function checkNum(num){
var i,j,strTemp
strTemp="0123456789"
if(num.length==0)
return 0
for(i=0i<num.lengthi++){
j=strTemp.indexOf(num.charAt(i))
if (j==-1){
return 0
}
}
return 1
}
<%
//函数名:chkid
//功能介绍:检查身份z
//参数说明:要检查的字符串
//返回值:0:不合格 1:合格
%>
function chkid(id){
if(id.length!=15 &&id.length!=18){
return 0
}
else if(chkspc(id)!=1){
return 0
}
else if(checkNum(id)==0){
return 0
}
else
return 1
}
<%
//函数名:checkZip
//功能介绍:检查是否为有效的邮政编码
//参数说明:要检查的数字
//返回值:1为是有效的,0为不是有效的
%>
function checkZip(zip){
if(zip.length!=6){
return 0
}
else if(checkNum(zip)==0){
return 0
}
}
<%
//检查电子邮件是否合法
//函数名:chkemail
//参数说明:要检查的字符串
//返回值:1:是
%>
function chkemail(a){
var i=a.length
var temp = a.indexOf('@')
var tempd = a.indexOf('.')
if(temp >1) {
if((i-temp) >3){
if((i-tempd)>0){
return 1
}
}
}
}
<%
//检查出生年份是否符合规定
//返回值:0:不正确 1:正确
%>
function chkYear(year){
if(year.length!=4)
return 0
if(checkNum(year)==0)
return 0
else if(chkspc(year)!=1)
return 0
else
return 1
}
-->
</script>
<script language="javascript">
var xmlHttp
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP")
}else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest()
}
}
function startRequest(){
createXMLHttpRequest()
xmlHttp.onreadystatechange = handleStateChange
var uname = document.getElementById("userName").value
xmlHttp.open("POST","RegAjax?name="+uname,true)
xmlHttp.send(null)
}
function handleStateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
if("t"==(xmlHttp.responseText))
alert("用户名已被占用")
}
}
}
</script>
</head>
<body>
<%
if("OK".equals(request.getSession().getAttribute("reginfo"))){
response.setHeader("refresh","2URL=../index.jsp")
%>
注册成功啦。<br>
两秒钟后返回首页,如果没有返回<br>
请点这里<a href="../index.jsp">返回</a>主页
<%
}else{
if(request.getSession().getAttribute("reginfo")!=null){
%>
<center><%=(String)request.getSession().getAttribute("reginfo") %></center>
<%} %>
<form name="RegInfoPost" method="post" action="reg.do">
<table width="615" height="617" border="0" align="center">
<tr><a href="./index.jsp">点这返回首页</a>
<td colspan="4"><hr color="#cccccc" noshade="yes" size="1"></td>
</tr>
<tr>
<td colspan="4"><hr color="#cccccc" noshade="yes" size="1"></td>
</tr>
<tr>
<td width="150" height="30" valign="top"><!--DWLayoutEmptyCell--> </td>
<td width="339" valign="middle">
<span class="style2"><strong>用户帐号:</strong></span>
<input name="userName" type="text" class="item_table" id="userName" maxlength="16" OnBlur="startRequest()">
<span class="error">*(6-16个字符)</span> </td>
<td width="126" valign="middle">
</td>
</tr>
<tr>
<td> </td>
<td valign="middle"><strong>用户密码:</strong> <input name="password" type="password" class="item_table" id="password" maxlength="16">
<span class="error">*(6-16个字符) </span> </td>
<td> </td>
</tr>
<tr>
<td height="30"> </td>
<td valign="middle"><strong>确认密码:</strong> <input name="password2" type="password" class="item_table" id="password2" maxlength="16">
<span class="error">*(请确认密码)</span> </td>
<td> </td>
</tr>
<tr align="center" valign="middle">
<td height="30" colspan="3" valign="middle"><hr color="#cccccc" noshade="yes" size="1"></td>
</tr>
<tr align="center" valign="middle">
<td height="20" colspan="3"><span class="error">密码保护(在您忘记密码时,将通过以下问题来重新获得您的密码)</span></td>
</tr>
<tr align="center" valign="middle">
<td height="30"> </td>
<td colspan="2" align="left" valign="middle"><strong>密码提示问题:</strong> <input name="question" type="text" class="item_table" id="question" maxlength="20">
<span class="error">*(不超过20个字符)</span> </td>
</tr>
<tr align="center" valign="middle">
<td height="30"> </td>
<td colspan="2" align="left" valign="middle"><strong>密码提示答案:</strong> <input name="answer" type="text" class="item_table" id="answer" maxlength="10">
<span class="error">*(不超过10个字符)</span> </td>
</tr>
<tr>
<td height="14" colspan="2" valign="top"><strong>姓名</strong><font color="#ff0000"><span class="error">*</span></td>
<td colspan="2" valign="top"><strong>身份z号码</strong><font color="#ff0000"><span class="error">*</span></td>
</tr>
<tr>
<td height="18" colspan="2" valign="top">
<input name="realName" type="text" id="realname"> </td>
<td colspan="2" valign="top"><input name="identityCard" type="text" id="identityCard" size="18" maxlength="18"></td>
</tr>
<tr>
<td width="116" height="14"> </td>
<td width="185"> </td>
<td width="127"> </td>
<td width="169"> </td>
</tr>
<tr>
<td><strong>国家或地区</strong><font color="#ff0000"><span class="error">*</span></td>
<td><strong>邮政编码</strong><font color="#ff0000"><span class="error">*</span></td>
<td><strong>省市自治区</strong><font color="#ff0000"><span class="error">*</span></td>
<td><strong>城市</strong><font color="#ff0000"><span class="error">*</span></td>
</tr>
<tr>
<td>
<select name="country" id="country">
<option selected>中国</option>
<option>中国香港</option>
<option>中国澳门</option>
<option>中国台湾</option>
</select>
</td>
<td>
<input name="zip" type="text" id="zip">
</td>
<td>
<select name="state" id="state" onclick="selectCity()">
<option value="default" selected name="value" isCity="false">选择省市自治区</option>
<option name="value" value="北京" isCity="true">北京</option>
<option name="value" value="上海" isCity="true">上海</option>
<option name="value" value="天津" isCity="true">天津</option>
<option name="value" value="重庆" isCity="true">重庆</option>
<option name="value" value="安徽省" isCity="false">安徽省</option>
<option name="value" value="福建省" isCity="false">福建省</option>
<option name="value" value="甘肃省" isCity="false">甘肃省</option>
<option name="value" value="广东省" isCity="false">广东省</option>
<option name="value" value="广西壮族自治区" isCity="false">广西壮族自治区</option>
<option name="value" value="贵州省" isCity="false">贵州省</option>
<option name="value" value="海南省" isCity="false">海南省</option>
<option name="value" value="河北省" isCity="false">河北省</option>
<option name="value" value="河南省" isCity="false">河南省</option>
<option name="value" value="黑龙江省" isCity="false">黑龙江省</option>
<option name="value" value="湖北省" isCity="false">湖北省</option>
<option name="value" value="湖南省" isCity="false">湖南省</option>
<option name="value" value="吉林省" isCity="false">吉林省</option>
<option name="value" value="江苏省" isCity="false">江苏省</option>
<option name="value" value="江西省" isCity="false">江西省</option>
<option name="value" value="辽宁省" isCity="false">辽宁省</option>
<option name="value" value="内蒙古自治区" isCity="false">内蒙古自治区</option>
<option name="value" value="宁夏回族自治区" isCity="false">宁夏回族自治区</option>
<option name="value" value="青海省" isCity="false">青海省</option>
<option name="value" value="山东省" isCity="false">山东省</option>
<option name="value" value="山西省" isCity="false">山西省</option>
<option name="value" value="陕西省" isCity="false">陕西省</option>
<option name="value" value="四川省" isCity="false">四川省</option>
<option name="value" value="台湾省" isCity="false">台湾省</option>
<option name="value" value="西藏自治区" isCity="false">西藏自治区</option>
<option name="value" value="新疆维吾尔自治区" isCity="false">新疆维吾尔自治区</option>
<option name="value" value="云南省" isCity="false">云南省</option>
<option name="value" value="浙江省" isCity="false">浙江省</option>
<option name="value" value="中国香港" isCity="true">中国香港</option>
<option name="value" value="中国澳门" isCity="true">中国澳门</option>
</select>
</td>
<td>
<input name="city" type="text" id="city" onfocus="checkCity()">
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4"><strong>送货地址</strong><font color="#ff0000"><span class="error">*</span></td>
</tr>
<tr>
<td colspan="4">
<input name="address" type="text" id="address" size="41">
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="2"><strong>主要联系电话</strong><font color="#ff0000"><span class="error">*</span></td>
</tr>
<tr>
<td colspan="2">
<input name="phone" type="text" id="phone">
</td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td colspan="4"><hr color="#cccccc" noshade="yes" size="1"></td>
</tr>
<tr>
<td colspan="4"><span class="error">请填写真实有效的电子邮件地址</span></td>
</tr>
<tr>
<td colspan="4"><strong>电子邮件地址<font color="#ff0000"></strong><span class="error">*</span></td>
</tr>
<tr>
<td colspan="4">
<input name="email" type="text" id="email" size="40"> </td>
</tr>
<tr>
<td colspan="4"><span class="style2">范例:</span><span class="style3"[email protected]</span></td>
</tr>
<tr>
<td colspan="4"><strong>请再一次输入您的电子邮件地址</strong><font color="#ff0000"><span class="error">*</span></td>
</tr>
<tr>
<td colspan="4">
<input name="email2" type="text" id="email2" size="40"> </td>
</tr>
<tr>
<td colspan="4"><hr color="#cccccc" noshade="yes" size="1"></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td> </td><td colspan="2"><div align="center"><strong>接受用户协议</strong></div></td>
</tr>
<tr>
<td height="87" colspan="4"><div align="center">
<textarea name="textarea" cols="70" rows="15" wrap="VIRTUAL"> 本网站仅为威迅教育交流学习之用,您必须无条件接受以下条件方可继续注册。
一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播下列信息:
(一)煽动抗拒、破坏宪法和法律、行政法规实施的;
(二)煽动颠覆国家政权,推翻社会主义制度的;
(三)煽动分裂国家、破坏国家统一的;
(四)煽动民族仇恨、民族歧视,破坏民族团结的;
(五)捏造或者歪曲事实,散布谣言,扰乱社会秩序的;
(六)宣扬封建迷信、淫秽、色情、赌博、暴力、凶杀、恐怖、教唆犯罪的;
(七)公然侮辱他人或者捏造事实诽谤他人的,或者进行其他恶意攻击的;
(八)损害国家机关信誉的;
(九)其他违反宪法和法律行政法规的;
(十)进行商业广告行为的。
二、互相尊重,对自己的言论和行为负责。</textarea>
</div></td>
</tr>
<tr>
<td colspan="4"><div align="center"><strong>当通过点击”注册“按钮即表示我已无条件接受以上协议</strong></div></td>
</tr>
<tr>
<td colspan="4"><hr color="#cccccc" noshade="yes" size="1"></td>
</tr>
<tr>
<td colspan="4"><div align="center">
<input type="submit" name="Submit" value="注册" onClick="return onSubmit()">
<input type="reset" name="Reset" value="重置">
</div></td>
</tr>
<tr>
<td height="46" colspan="4"> </td>
</tr>
</table>
</form>
<%} %>
</body>
</html>
你可以把最顶部要显示的东西做一个页面,比如叫 header.jsp,这个页面就放用户登录信息比如你说的 【 A用户,欢迎你!退出 】等等。
你在登录后,声明sesson对象
把用户信息放到session。
session.setAttribute("userInfo", userInfo)
然后在每个页面用JSP指令把该页面导入到要显示的页面就OK啦。
header.jsp页面
${sessionScope.userInfo.username} 用户,欢迎您
<%@ include file="header.jsp"%>
这样就会达到你想要的效果。
如果还有不明白的,就追问我啦。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)