如何实现某个jsp页面转到action判断错误之后输出错误提示信息再回到这个jsp页面用alert输出错误信息?

 我来答
百度网友dc81944bb
2009-11-02 · TA获得超过572个赞
知道小有建树答主
回答量:793
采纳率:0%
帮助的人:715万
展开全部
这个。你用在action后台那里request.setAttribute("errors","错误了!");return false. 再struts里配置false回到这个页面,在开头那String errorinfo = request.getAttribute("errors")之后。用一个写一点js..看看这个if(<%=errorinfo%>!=null){
alert("(<%=errorinfo%>");

}
大时代暑
2009-11-01 · TA获得超过2.5万个赞
知道大有可为答主
回答量:4111
采纳率:0%
帮助的人:4772万
展开全部
<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>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
上帝爱静静
2009-11-02 · 超过18用户采纳过TA的回答
知道答主
回答量:240
采纳率:0%
帮助的人:59.9万
展开全部
在action中 request.setAttribute("ErrorMessages",errormessage);
应该回到这个页面onload调用一个函数。函数里面alert("${ErrorMessages}");
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
pujia12345
2009-11-01 · TA获得超过3680个赞
知道大有可为答主
回答量:3456
采纳率:0%
帮助的人:2938万
展开全部
javascript定时执行window.href=地址。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式