java.lang.nullpointerexception

DecadeScript 2013-12-20 11:48:45
小白求助,在编译servlet出现了如题的报错 代码如下 这里一个登录验证的处理 在线等
纠结了我好久



//用户验证

package com.yxl;


import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginCl extends HttpServlet{

public void doGet(HttpServletRequest req , HttpServletResponse res)
throws ServletException, IOException {

res.setContentType("text/html;charset=UTF-8");



//接受
String u = req.getParameter("username");
String p = req.getParameter("password");

if(u.equals("yxl")&&p.equals("123")){
//合法

res.sendRedirect("wel?uname="+u); //把username传递给wel界面
}else{
//不合法
res.sendRedirect("login");
}

}

public void doPost(HttpServletRequest req , HttpServletResponse res)
throws ServletException, IOException {
this.doGet(req,res);
}
}
...全文
158 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
DecadeScript 2013-12-20
  • 打赏
  • 举报
回复
引用 6 楼 u010703975 的回复:
[quote=引用 4 楼 fudongrifdr 的回复:] 加个非空判断
我试下[/quote] 这个也有用 可是跳转后是个空白界面
DecadeScript 2013-12-20
  • 打赏
  • 举报
回复
引用 4 楼 fudongrifdr 的回复:
加个非空判断
我试下
DecadeScript 2013-12-20
  • 打赏
  • 举报
回复
引用 2 楼 ghw554557313 的回复:
u或者p是null, 反过来写: "yxl".equals(u) && "123".equals(p) 记住,用equals判断String时,常量一般写在前面,这样可以防止NullPointer
谢谢这个有用 我按照你说的改了 可是它就无法跳转到欢迎界面了 老是跳转到登录界面 我有三个java文件 一个是登录的 这个可以编译 还有一个是登录验证的 最后就是欢迎界面了
末日哥 2013-12-20
  • 打赏
  • 举报
回复
加个非空判断
DecadeScript 2013-12-20
  • 打赏
  • 举报
回复
引用 1 楼 qiyuexuel 的回复:
界 面 呢,
是要看报错界面吗 报错代码如下 HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.NullPointerException com.yxl.LoginCl.doGet(LoginCl.java:26) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java:728) note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs. -------------------------------------------------------------------------------- Apache Tomcat/7.0.47
ghw554557313 2013-12-20
  • 打赏
  • 举报
回复
u或者p是null, 反过来写: "yxl".equals(u) && "123".equals(p) 记住,用equals判断String时,常量一般写在前面,这样可以防止NullPointer
齐岳 2013-12-20
  • 打赏
  • 举报
回复
界 面 呢,

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧