解决方案 »

  1.   

    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    String username = request.getParameter("username");
    String password = request.getParameter("password");boolean flag = false;
    if(username.equals("lc") && password.equals("123"))
    {
    flag = true;
    }request.setAttribute("isSuccess", flag);
    request.getRequestDispatcher("/info.jsp").forward(request, response);
    }
    在这个方法里加个断点看看
    username和password的值有没有传过来
      

  2.   

    java.lang.NullPointerException // 空指针异常
    bbk.LoginServlet.doGet(LoginServlet.java:22) // doGet方法的22行,不知道是不是这行if(username.equals("lc") && password.equals("123"))
    换成if("lc".equals(username) && "123".equals(password))试试
      

  3.   

    if(username.equals("lc") && password.equals("123"))
    request.getParameter( ); 获取到的参数为String 类型的,如果参数不存在,那么会返回null,这样就出现空指针了
    使用username 和 password 之前可以先判空,然后再调用equals  方法
    或者 将常量写在前面,if("lc".equals(username) 来规避空指针问题
    检查下参数的大小写问题,避免因大小写导致的空指针
      

  4.   

    根本就没把username和password的值传到后台吧
      

  5.   

    那说明你的username和password还至少有一个没有传到后台,检查下你的form表单字段的定义吧
    使用上面的写法可以帮忙规避掉空指针问题,但并没有解决以前的没有接收到传值的问题
    或者 把你的提交页面发出来吧,让大家帮你看看问题
      

  6.   

    那说明你的username和password还至少有一个没有传到后台,检查下你的form表单字段的定义吧
    使用上面的写法可以帮忙规避掉空指针问题,但并没有解决以前的没有接收到传值的问题
    或者 把你的提交页面发出来吧,让大家帮你看看问题
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'login.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
      <form action="LoginServlet" method="post">
      <input type="text" name="username">
      <input type="password" name="password">
      <input type="submit">
      </form>
      </body>
    </html>
    这个应该就是提交页面吧。
      

  7.   

    那说明你的username和password还至少有一个没有传到后台,检查下你的form表单字段的定义吧
    使用上面的写法可以帮忙规避掉空指针问题,但并没有解决以前的没有接收到传值的问题
    或者 把你的提交页面发出来吧,让大家帮你看看问题
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'login.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
      <form action="LoginServlet" method="post">
      <input type="text" name="username">
      <input type="password" name="password">
      <input type="submit">
      </form>
      </body>
    </html>
    这个应该就是提交页面吧。
    没有传值的操作吧
      

  8.   

    在后台输出username和password看看
      

  9.   

    if ((null != username) && (null != password) && "lc".equals(username.trim()) && "123".equals(password.trim())) 进行判断
    防止传进来的username 或者 password 前后有空字符的影响
      

  10.   

    那说明你的username和password还至少有一个没有传到后台,检查下你的form表单字段的定义吧
    使用上面的写法可以帮忙规避掉空指针问题,但并没有解决以前的没有接收到传值的问题
    或者 把你的提交页面发出来吧,让大家帮你看看问题
    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <base href="<%=basePath%>">
        
        <title>My JSP 'login.jsp' starting page</title>
        
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->  </head>
      
      <body>
      <form action="LoginServlet" method="post">
      <input type="text" name="username">
      <input type="password" name="password">
      <input type="submit">
      </form>
      </body>
    </html>
    这个应该就是提交页面吧。
    没有传值的操作吧我这是看的教学视频,教的第一个web程序,好多知识都还不懂?您能教我怎么修改下么??
      

  11.   

    String username = request.getParameter("username");
    String password = request.getParameter("password");
    System.out.println("username=" + username);
    System.out.println("password=" + password );
    看看需要的username和password有没有传递到后台
      

  12.   

    就加到你后台的servlet里面
    结果会在tomcat控制台打印出来,如果是eclipse集成的tomcat,那就在eclipse的控制台打印出来
      

  13.   

    看到了,tomcat控制台显示这两个值都是null,这是怎么造成的?问题是不是出在登陆界面上??应该怎么修改下??
      

  14.   

    我自己把问题解决了!哈哈!
    我相信楼上各位大神做梦都没想到我这个新手白痴是怎么犯的错我应该先在浏览器运行login.jsp的,而不是上来直接运行servlet,作为个新手真是太白痴了,还是感谢楼上各位今晚的付出,谢谢你们了!