使用JavaScript和JSP重定向到另一个页面 [英] Redirecting to another page with JavaScript and JSP

查看:74
本文介绍了使用JavaScript和JSP重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注册后,我正在尝试使用JSP或JavaScript将用户重定向到我的登录页面.

I am trying to redirect the user to my log in page as soon as the registration is done, using either JSP or JavaScript.

我应该提到注册表格正在调用同一页面,当我说window.location时,glassfish会因为找不到资源而抛出错误.

I should mention that the registration form is calling the same page and when I say window.location, glassfish throws error as resource not found.

                                   {
    if(request.getParameter("submit")!=null)
                   {
        String uname=request.getParameter("txtusername");
        String password=request.getParameter("txtpassword");
        String mail=request.getParameter("txtemail");
        String dob=request.getParameter("dob");
        String city=request.getParameter("txtcity");
        String state=request.getParameter("txtstate");
        String country=request.getParameter("txtcountry");
        String address=request.getParameter("txtstreetaddress");
        String scity=request.getParameter("txtscity");
        String sstate=request.getParameter("txtsstate");
        String scountry=request.getParameter("txtscountry");
        String saddress=request.getParameter("txtsaddress");
        String mobile=request.getParameter("txtno");
        String gender=request.getParameter("rdbgender");
             adminClasses.user u= new adminClasses.user(0, uname, password, mail, dob, city, state, country, address, scity, sstate, scountry, saddress, mobile, gender);
              int result=adminClasses.userfunctions.addNewUser(u);
                    %>
                    <script>
                        var res=<%=result%>;
                        if(res==0)
                            {
                               window.alert("Registration Unsuccessful");
                            }
                            else
                                {
                                    window.alert("Resgistration Successful!Click Ok to Sign in");
                                    window.location="signin.jsp";
                                }
                    </script>
                    <%                  
                                           }
                              }
       catch (Exception e)
                                     {
                    out.println(e.getMessage());
                   }

推荐答案

我认为您可以这样做:

...
int result = adminClasses.userfunctions.addNewUser(u);

if (result == 0) {
    request.getRequestDispatcher("signupSuccess.jsp").forward(request, response);
}
...

它将在服务器端评估result,然后根据result,将转发到signupSuccess.jsp页面–即URL将保持不变,但响应将包括成功页面的评估内容

It will evaluate the result on the server side and then, depending on the result, will forward to a signupSuccess.jsp page – i.e. the URL will stay the same, but the response will include success page's evaluated content.

这篇关于使用JavaScript和JSP重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆