如果用户名或密码输入错误,网页就像没有跳转过一样,把错误信息提示在登录框的上面 如下图    

解决方案 »

  1.   

    ajax          --------------------请输入至少为6的字符串
      

  2.   

    页面不跳转 ajax专门干这个的 搜索下ajax吧
      

  3.   

    看看这个行不行  http://blog.sina.com.cn/s/blog_7671643b01015ryj.html 
      

  4.   

    如果跳转的话,可以在jsp页面用el表达式,第一次访问没有就什么都不显示,提交到服务器发现密码不对就回传回来,然后el表达式就能显示了,并且可以用jstl根据有没有回传错误信息判断密码框是不是显示红色边框
      

  5.   

    ajax,这个技术还是很有用的,需要注册时都会用到的
      

  6.   

    1.如果不跳转的实现,那就用ajax。这样可以增加用户体验。
    2.如果跳转的话,可以在jsp页面用el表达式,
    第一次访问没有就什么都不显示,经过服务器验证发现密码不正确,跳转至登录页面,传入一个错误提示信息
    然后el表达式就能显示了。字体的颜色可以用css来修饰。
      

  7.   

    在你的Action方法里面加上super.addActionError("用户名或者密码错误"); 
      

  8.   


    大侠 不知道应该怎么传递参数 
    我使用的是SSH框架 用DispatchAction里面的东西跳转页面
      

  9.   

    你不会传递参数是怎么使用struts框架的。
    在你传递到后台的请求后面加上参数即可。
    比如请求的是LoginAction,参数是name="xhx"
    url="LoginAction?name='xhx'"
      

  10.   


    大侠  这个好想不行也  失去焦点时  进入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>
    不知道是不是哪里出了问题 其他的都可那个例子差不多 .. 请多指教 .. 
      

  11.   

    就像上面都说的,用ajax,在SSH里面,action返回值为null,使用printer打印你的返回结果,根据返回结果判断显示或跳转。
    比如,返回true,那么就跳转,返回false,就把error message设置到那个空白的error控件(一般都是加一个空白的label)就是了。
      

  12.   

    额。。应该说是没有返回值(void类型),为空也可以,但是会报一个你影响结果的异常,看着不舒服。
      

  13.   

    终于好了 谢谢各位 接下来分享一下 
    不过我没有用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>
       密&nbsp;&nbsp;码:<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>前辈多指教
      

  14.   

    你当前这样实现会刷新页面,在用户体验上可能稍微差一点。
    另外,我建议String flag = (String)request.getAttribute("flag")取值后就移除掉这个属性,以免对以后有影响。实质上用ajax很简单的,不用想那么复杂,特别是jquery的ajax实现,就一个方法而已。
      

  15.   


    是吗 谢谢 
    Ajax 不知道怎么用啊 如果在这个基础上修改的话 前辈有没有什么建议? 
      

  16.   

    如果要求不高,就用这种方式也没什么关系,影响不大。
    我也是来学习的,不算什么前辈,呵呵。
    <%
        String flag = (String)request.getAttribute("flag");
        request.removeAttribute("flag");
    %>