if((u_name.equals(rs.getString("name")))&&(u_password.equals(rs.getString("password"))))
{
response.setContentType("text/html; charset=gb2312");
                                             //当条件成立时可以转向blog.jsp界面
response.sendRedirect("/www/blog.jsp");
}
else
{
                                                  //当条件 不成立时为什么就不能转向index.jsp界面呢?
response.setContentType("text/html; charset=gb2312");
response.sendRedirect("/index.jsp");

}

解决方案 »

  1.   

    request.getRequestDispatcher("/www/blog.jsp").forward(request, response);
      

  2.   

       response.setContentType("text/html; charset=gb2312");  
       if((u_name.equals(rs.getString("name")))&&(u_password.equals(rs.getString("password"))))
                        {
                          
                                                 //当条件成立时可以转向blog.jsp界面
                            response.sendRedirect("/www/blog.jsp");
                        }
                        else
                        {
                                                      //当条件 不成立时为什么就不能转向index.jsp界面呢?
                            
                        response.sendRedirect("/index.jsp");
                            
                        }  
    注意路径
      

  3.   


    if(u_name.equals(rs.getString("name"))&&u_password.equals(rs.getString("password")))
    {
    response.setContentType("text/html; charset=gb2312"); response.sendRedirect("/www/blog.jsp");
    return;
    }
    else
    {
    response.setContentType("text/html; charset=gb2312");
    response.sendRedirect("http://localhost:8080/www/index.jsp");
    return;//加上return也不起作用 
    }
      

  4.   

    错误信息是什么?
    www是不是项目根路径?
    forward跳转到的页面不必写全路径名,而sendRedirect必须写全路径名
    forward跳转与重定向的区别:
    a.forward跳转到的页面能够接受到request设置的属性,
      而sendRedirect不能(所它得使用比request范围更广的session设置属性)
    b.forward跳转到的页面不必写全路径名,而sendRedirect必须写全路径名  
    c.forward不能跳转到此web项目以外的连接,而sendRedirect可以跳转到此web项目以外的连接
    d.forward跳转后地址栏显示不变,而sendRedirect跳转后显示的是目标的地址信息
    e.forward跳转的速度相对而言比sendRedirect跳转的速度要快     
      

  5.   

    如果bolg.jsp与index.jsp在同一目录下response.sendRedirect("/www/index.jsp");
      

  6.   

    登陆页面是http://127.0.0.1:8080/www/
    登陆失败时是一个空白页面http://127.0.0.1:8080/user_y.do
    本打算用out.print(e)输出异常
    但是还是输出没有
    并没有转向index.jsp页面
    //index.html
    <html>
    <head>
    <title>Welcome to Hello,World!</title>
    <link rel="stylesheet" type="text/css" href="css1.css">
    <Meta http-equiv="Content-Type" Content="text/html; Charset=gb2312">

    </head>
    <body>
    <div id=box>


    <div id=head><div id=head_1>&nbsp Hello,World!</div></div>

    <div id=left>

    </div>




    <div id=right_right>

    <form action="/user_y.do" method=post >
    <table   style="font-family:Times;color:mediumslateblue">
    <tr>
    <td>&nbsp Name:</td>
    </tr>
    <tr>
    <td>&nbsp <input type=text name=username size=20 ></td>
    </tr>
    <tr>
    <td>&nbsp Password:</td>
    </tr>
    <tr>
    <td>&nbsp <input type=password name=password ></td>
    </tr>
    <tr>
    <td>&nbsp <input type=submit style="background-color:mediumslateblue; color:white;" name=edit value="登录" >&nbsp;<a href=register.jsp>注册</a></td>
    </tr>
    </table>
    </form>
    </div>





    <div>
    </body>
    </html>//user_y.do
    import java.io.*;
    import java.util.*;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.sql.*;public class User_y extends HttpServlet
    {
    private String user;
    private String password;
    private String host;
    private String db_Driver;
    private String path;
    private Statement stmt=null;
    private ResultSet rs=null;
    private Connection con; public void init() throws ServletException
    {

    ServletContext config=getServletContext();
    user=config.getInitParameter("user");
    password=config.getInitParameter("password");
    host=config.getInitParameter("host");
    db_Driver=config.getInitParameter("db_Driver");
    path=config.getInitParameter("path");


    }
    public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
    {

    request.setCharacterEncoding("gb2312");
    response.setContentType("text/html");
    response.setCharacterEncoding("gb2312");
    PrintWriter out=response.getWriter();

    String u_name=request.getParameter("username");
    String u_password=request.getParameter("password");






    try
    {
    Class.forName(db_Driver);
    con=DriverManager.getConnection(host,user,password);

    String sql="select * from user where name='"+u_name+"' and password='"+u_password+"'";
    stmt=con.createStatement();
    ResultSet rs=stmt.executeQuery(sql);

    if(rs.next())
    {

    if(u_name.equals(rs.getString("name"))&&u_password.equals(rs.getString("password")))
    {
    response.setContentType("text/html; charset=gb2312"); response.sendRedirect("/www/blog.jsp");
    return;
    }
    else
    {
    try
    {
    response.sendRedirect("index.jsp");
    return;
    }
    catch (Exception e)
    {
    out.print("10"+e); }


    }



    }

    }
    catch (Exception e)
    {
    out.print("1"+e); } finally
    {
    try
    {
    stmt.close();
    con.close();
    }
    catch (Exception e)
    {
    out.print("3"+e);
    }
    }

    }
    }
      

  7.   

    嗯~~上面的
     response.sendRedirect("index.jsp");
     return;
    应该改成 response.sendRedirect("/www/index.jsp");
     return;
      

  8.   

    把项目名加上就行了,
    比如说你我项目是  book 那么就 /book/xxx.jsp
      

  9.   

     response.sendRedirect("../index.jsp");
      

  10.   

    这么说吧 你刚才那段public class User_y extends HttpServlet...
    如果你写在servlet中,那就是在服务器中了,经过服务器了就不用把你的项目目录打出来了,因为服务器是黙指到你的项目目录底下的,如果你是在jsp中,也就是html跳转,那就要把路径打全,项目根目录也要带上,因为这是在客户端的,不经过服务器...