如何实现某个jsp页面转到action判断错误之后输出错误提示信息再回到这个jsp页面用alert输出错误信息?
4个回答
展开全部
<html>
<head>
<title>欢乐聊天室</title>
</head>
<body bgcolor="#99CCFF">
<p align="center"><b><font face="隶书" size="6" color="#FF00FF">欢乐聊天室</font></b></p>
<p align="center"><b>请输入您的聊天用户名</b></p>
<form method="POST" action="login.jsp">
<p align="center"><input type="text" name="inputid" size="20"></p>
<p align="center"><input type="submit" value="确定" name="B1"> <input type="reset" value="取消" name="B2"></p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>欢乐聊天室</title>
</head>
<body>
<%--首先取出用户提交的代号名称,保存在变量chatid中--%>
<%
String chatid = new String();
chatid = request.getParameter("inputid");
%>
<%--使用变量flag来标记用户输入是否合法,如果合法,则flag为true --%>
<%
boolean flag;
flag = true;
if(chatid == null){
chatid = "";
}
if(chatid.length() == 0){
flag = false;
}
%>
<%--比较用户所输入的id和目前聊天室中存在的所有id --%>
<%
for(int i=1; i<=6 && flag; i++){
String itemp = new String();
itemp = itemp.valueOf(i);
int num;
String numtemp = new String();
String temp = new String();
temp = "room" + itemp + "usernum";
numtemp = (String)application.getAttribute(temp);
if(numtemp == null){
numtemp = "0";
application.setAttribute(temp ,numtemp);
}
num = Integer.parseInt(numtemp);
for(int j=1; j<=num && flag; j++){
String jtemp = new String();
jtemp = jtemp.valueOf(j);
%>
<%--从application对象中取出第i个聊天室中第j个用户的id,temp变量保存的是application对象用于保存第i个聊天室中第j个用户的id相应的变量名 --%>
<%
temp = "room" + itemp + "user" + jtemp;
String usertemp = new String();
usertemp = (String)application.getAttribute(temp);
if(usertemp.equalsIgnoreCase(chatid)){
flag = false;
}
}
}
int nnn[] = new int[6];
if(flag){
String temproom = new String();
temproom = (String)session.getValue("chatroom");
if(temproom == null){
session.putValue("chatid",chatid);
}
for(int i=1; i<=6; i++) {
String itemp = new String();
itemp = itemp.valueOf(i);
int num;
String numtemp = new String();
String temp = new String();
temp = "room" + itemp + "usernum";
numtemp = (String)application.getAttribute(temp);
if(numtemp == null){
numtemp = "0";
}
num = Integer.parseInt(numtemp);
nnn[i-1] = num;
}
}
%>
<p align="center"><b><font face="隶书" size="6" color="#FF00FF">欢乐聊天室</font></b></p>
<%
if(flag){
%>
<p align="center"><font color="red"><%=chatid %></font>您好,请选择感兴趣的聊天室!</p>
<center><table border="1" width="370">
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=1">今天我们相识(<%=nnn[0]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=2">校园的那条小路(<%=nnn[1]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=3">职场淘金(<%=nnn[2]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=4">网络技术交流(<%=nnn[3]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=5">世界体育大看台(<%=nnn[4]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=6">新闻背后的故事(<%=nnn[5]%>)</a></td>
</tr>
</table><center>
<%
}else {
%>
<center><p>id不能为空,或者此id已经被使用,请重新选择!</p><center>
<p><center><a href="login.html">返回</a><center></p>
<%
}
%>
</body>
</html>
<head>
<title>欢乐聊天室</title>
</head>
<body bgcolor="#99CCFF">
<p align="center"><b><font face="隶书" size="6" color="#FF00FF">欢乐聊天室</font></b></p>
<p align="center"><b>请输入您的聊天用户名</b></p>
<form method="POST" action="login.jsp">
<p align="center"><input type="text" name="inputid" size="20"></p>
<p align="center"><input type="submit" value="确定" name="B1"> <input type="reset" value="取消" name="B2"></p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=gb2312"
pageEncoding="gb2312"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>欢乐聊天室</title>
</head>
<body>
<%--首先取出用户提交的代号名称,保存在变量chatid中--%>
<%
String chatid = new String();
chatid = request.getParameter("inputid");
%>
<%--使用变量flag来标记用户输入是否合法,如果合法,则flag为true --%>
<%
boolean flag;
flag = true;
if(chatid == null){
chatid = "";
}
if(chatid.length() == 0){
flag = false;
}
%>
<%--比较用户所输入的id和目前聊天室中存在的所有id --%>
<%
for(int i=1; i<=6 && flag; i++){
String itemp = new String();
itemp = itemp.valueOf(i);
int num;
String numtemp = new String();
String temp = new String();
temp = "room" + itemp + "usernum";
numtemp = (String)application.getAttribute(temp);
if(numtemp == null){
numtemp = "0";
application.setAttribute(temp ,numtemp);
}
num = Integer.parseInt(numtemp);
for(int j=1; j<=num && flag; j++){
String jtemp = new String();
jtemp = jtemp.valueOf(j);
%>
<%--从application对象中取出第i个聊天室中第j个用户的id,temp变量保存的是application对象用于保存第i个聊天室中第j个用户的id相应的变量名 --%>
<%
temp = "room" + itemp + "user" + jtemp;
String usertemp = new String();
usertemp = (String)application.getAttribute(temp);
if(usertemp.equalsIgnoreCase(chatid)){
flag = false;
}
}
}
int nnn[] = new int[6];
if(flag){
String temproom = new String();
temproom = (String)session.getValue("chatroom");
if(temproom == null){
session.putValue("chatid",chatid);
}
for(int i=1; i<=6; i++) {
String itemp = new String();
itemp = itemp.valueOf(i);
int num;
String numtemp = new String();
String temp = new String();
temp = "room" + itemp + "usernum";
numtemp = (String)application.getAttribute(temp);
if(numtemp == null){
numtemp = "0";
}
num = Integer.parseInt(numtemp);
nnn[i-1] = num;
}
}
%>
<p align="center"><b><font face="隶书" size="6" color="#FF00FF">欢乐聊天室</font></b></p>
<%
if(flag){
%>
<p align="center"><font color="red"><%=chatid %></font>您好,请选择感兴趣的聊天室!</p>
<center><table border="1" width="370">
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=1">今天我们相识(<%=nnn[0]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=2">校园的那条小路(<%=nnn[1]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=3">职场淘金(<%=nnn[2]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=4">网络技术交流(<%=nnn[3]%>)</a></td>
</tr>
<tr>
<td width="50%"><a href="JSPchat.jsp?chatroom=5">世界体育大看台(<%=nnn[4]%>)</a></td>
<td width="50%"><a href="JSPchat.jsp?chatroom=6">新闻背后的故事(<%=nnn[5]%>)</a></td>
</tr>
</table><center>
<%
}else {
%>
<center><p>id不能为空,或者此id已经被使用,请重新选择!</p><center>
<p><center><a href="login.html">返回</a><center></p>
<%
}
%>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在action中 request.setAttribute("ErrorMessages",errormessage);
应该回到这个页面onload调用一个函数。函数里面alert("${ErrorMessages}");
应该回到这个页面onload调用一个函数。函数里面alert("${ErrorMessages}");
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
javascript定时执行window.href=地址。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询