public String userLogin() throws Exception{
//获得页面传入的名称
String usname=petinfo.getPetName().trim();
//获得页面传入的密码
String upwd=petinfo.getPetPassword().trim();
if(usname!=null&&!"".equals(usname)){
System.out.println("aaaaa");
}
else{
System.out.println("11111");
response.getWriter().println("<script>alert('名称不能为空!');history.back();</script>");
}
if(upwd!=null&&!"".equals(upwd)){
System.out.println("bbbbb");
}
else{
System.out.println("22222");
response.getWriter().println("<script>alert('密码不能为空!');history.back();</script>");
}
return "userLogin";
}我在 action中写了这个,其中 response.getWriter().println("<script>alert('密码不能为空!');history.back();</script>"); 有问题吗? 为什么我在页面上输出的时候在空值的情况下 可以打出 11111,22222 就是不能弹出alert()中的值???
//获得页面传入的名称
String usname=petinfo.getPetName().trim();
//获得页面传入的密码
String upwd=petinfo.getPetPassword().trim();
if(usname!=null&&!"".equals(usname)){
System.out.println("aaaaa");
}
else{
System.out.println("11111");
response.getWriter().println("<script>alert('名称不能为空!');history.back();</script>");
}
if(upwd!=null&&!"".equals(upwd)){
System.out.println("bbbbb");
}
else{
System.out.println("22222");
response.getWriter().println("<script>alert('密码不能为空!');history.back();</script>");
}
return "userLogin";
}我在 action中写了这个,其中 response.getWriter().println("<script>alert('密码不能为空!');history.back();</script>"); 有问题吗? 为什么我在页面上输出的时候在空值的情况下 可以打出 11111,22222 就是不能弹出alert()中的值???
解决方案 »
- spring3.0M3 关于Date类型自定义编辑器的问题
- Spring配置文件提示错误。。。。。
- about target
- struts中的文件下载?
- 我在用JFreechart创建曲线图的时候总是出这个错,只能用建立DAY的实列,FixedMillisecond, Hour, Millisecond, Minute, Month, Quarter,
- 急~~~struts流程问题
- 如何同时提供c平台和java平台的开发接口??
- 在实体bean中如何连接数据库
- J2EE基础问题
- axis2 客户端访问报Read timed out
- Spring+hibernate为什么save的时候差不进数据用了spring的getHibernateTemplate().save()
- struts2+hibernate问题
在那个错误页面里显示一下这个<script>alert('名称不能为空!');history.back(); </script>");
试试!
以上代码写在userLogin对应的jsp页面
定一个hidden,给这个hidden指定值,写一个js方法,检测这个hidden的值,当这个hidden的值变化的时候,执行js方法,js方法里面放history.back();
楼主好多response
这样是不对的
利用Struts2里的workflow interceptor,
当你有ActionError或者FieldError时跳转到"input"。public PetInfo petinfo;public String userLogin() {
//不要加throws Exception,只加可预测的错误
//获得页面传入的名称
String usname=petinfo.getPetName().trim();
//获得页面传入的密码
String upwd=petinfo.getPetPassword().trim();
if(usname!=null&&!"".equals(usname)){
System.out.println("aaaaa");
}
else{
System.out.println("11111");
addActionError("名称不能为空");
}
if(upwd!=null&&!"".equals(upwd)){
System.out.println("bbbbb");
}
else{
System.out.println("22222");
addActionError("密码不能为空!");
} return "userLogin";
} 在你的view页面里加上
<s:actionerror/>