如果用户名或密码输入错误,网页就像没有跳转过一样,把错误信息提示在登录框的上面 如下图
解决方案 »
- ext 初学者提问。。。。。。
- mysql 的数据库表生成hibernate的问题。。。。。。急
- spring中注解AOP编程一个小问题.
- 求一Map排序算法
- richfaces 的include问题
- 广域网访问RMI出错
- 请问,哪位兄弟有孙卫琴编写的精通Hibernate Java对象持久化技术详解的随书光碟呀。能不能传我一份呀。
- 在ibatis中实现分页,其中取得记录总数的问题!
- 求《J2EE应用与BEA Weblogic Server》和《软件工程Java语言实现》下载地址 (电子图书版块发不上,借宝地)
- 各位java高手,能否提供关于ejb开发的实例及说明,谢谢
- 外行简单的问题
- eclipse中 java程序怎样调用python?
2.如果跳转的话,可以在jsp页面用el表达式,
第一次访问没有就什么都不显示,经过服务器验证发现密码不正确,跳转至登录页面,传入一个错误提示信息
然后el表达式就能显示了。字体的颜色可以用css来修饰。
大侠 不知道应该怎么传递参数
我使用的是SSH框架 用DispatchAction里面的东西跳转页面
在你传递到后台的请求后面加上参数即可。
比如请求的是LoginAction,参数是name="xhx"
url="LoginAction?name='xhx'"
大侠 这个好想不行也 失去焦点时 进入javascript 然后好像没有进入后台判断的感觉
在javascript中 我修改了一下连接的URL 我是这样写的(我使用的是SSH):
var url = "/login.do?operation=login&userName="+encodeURI(userName);
这个url路径指向一个 DispatchAction
在struts配置文件中是这样的:<action path="/login" type="com.mulan.struts.action.LoginAction" parameter="operation">
<set-property property="cancellable" value="true" />
<forward name="index" path="/index.jsp" />
</action>
不知道是不是哪里出了问题 其他的都可那个例子差不多 .. 请多指教 ..
比如,返回true,那么就跳转,返回false,就把error message设置到那个空白的error控件(一般都是加一个空白的label)就是了。
不过我没有用Ajax Ajax下来以后再看 再次感谢各位 .. 框架是SSH这是那个DispatchActionpublic class LoginAction extends DispatchAction {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String temail = null;
String tpass = null;
/**
* 链接数据池
*/
DateSource ds = new DateSource();
try {
con = ds.getDate();
} catch ( Exception e ) {
e.printStackTrace();
}
//获得前台数据
temail = request.getParameter("temail");
tpass = request.getParameter("tpass");
/**
* 登录判断
*/
try {
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM treasure WHERE temail='" + temail + "'");
if (rs.next() == true ) {
if ( new Encrypt(tpass).checkEncryptString(rs.getString("tpass")) ) {
request.setAttribute("flag", "登录成功!");
} else {
request.setAttribute("flag", "密码输入错误");
}
} else {
request.setAttribute("flag", "用户名不存在");
}
return mapping.findForward("index");
} catch ( Exception e ) {
e.printStackTrace();
}
return null;
}
这是页面HTML
<%
String flag = (String)request.getAttribute("flag");
%>
<form action="login.do?operation=login" method="POST">
<%
if ( flag != null ) {
%>
<div id="cwxx" align="center" style="font-size:12px; background-color:#FF3366"> <%=flag %> </div>
<%
}
%>
用户名:<input type="text" name="temail" onblur=""><br>
密 码:<input type="password" name="tpass"><br>
<input type="submit" value="提交">
</form>最后是struts配置文件<action path="/login" type="com.mulan.struts.action.LoginAction" parameter="operation">
<set-property property="cancellable" value="true" />
<forward name="index" path="/index.jsp" />
</action>前辈多指教
另外,我建议String flag = (String)request.getAttribute("flag")取值后就移除掉这个属性,以免对以后有影响。实质上用ajax很简单的,不用想那么复杂,特别是jquery的ajax实现,就一个方法而已。
是吗 谢谢
Ajax 不知道怎么用啊 如果在这个基础上修改的话 前辈有没有什么建议?
我也是来学习的,不算什么前辈,呵呵。
<%
String flag = (String)request.getAttribute("flag");
request.removeAttribute("flag");
%>