为什么报错

为什么报错

package com.imooc.servlet;


import java.io.IOException;

import java.util.ArrayList;

import java.util.List;


import javax.servlet.ServletException;

import javax.servlet.annotation.WebServlet;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;


import com.imooc.domain.User;

import com.imooc.service.UserService;

import com.imooc.serviceImpl.UserServiceImpl;


@WebServlet("/RegistServlet")

public class RegistServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

request.setCharacterEncoding("UTF-8");

response.setContentType("text/html;charset=utf-8");

String username=request.getParameter("username");

String password=request.getParameter("password");

User user=new User();

user.setUsername(username);

user.setPassword(password);

System.out.println(user);

UserService userService=new UserServiceImpl();

List<User> userList=(List<User>)getServletContext().getAttribute("userlist");

userService.regist(userList, user);

System.out.println(userList);

//System.out.println(userList);

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

}



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

doGet(request, response);

}


}

package com.imooc.service;


import java.util.List;


import com.imooc.domain.User;


public interface UserService {

public void regist(List<User> userlist,User user);


}

package com.imooc.serviceImpl;


import java.util.ArrayList;

import java.util.List;


import com.imooc.domain.User;

import com.imooc.service.UserService;


public class UserServiceImpl implements UserService{


@Override

public void regist(List<User> userList, User user) {

// 保存用户信息

userList.add(user);

}


}

package com.imooc.domain;


public class User {

private String username;

private String password;

private String file;

public User(){

}

public User(String name, String password, String file) {

super();

this.username = name;

this.password = password;

this.file = file;

}

public String getName() {

return username;

}

public void setUsername(String name) {

this.username = name;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public String getFile() {

return file;

}

public void setFile(String file) {

this.file = file;

}

@Override

public String toString() {

return "User [name=" + username + ", password=" + password + ", file=" + file + "]";

}



}


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
好帮手慕小班 2020-01-04 16:11:07

同学你好,请问同学的报出什么错误,404、500错误吗,具体的报错信息是什么,是NullPointerException空指针异常的错误吗,还麻烦同学将具体的浏览器报错截图以及控制台的报错信息具体的贴出,便于老师根据错误定位问题。

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

  • 提问者 cj啦啦啦啦 #1
    是NullPointerException空指针异常
    2020-01-04 16:17:12
  • 好帮手慕小班 回复 提问者 cj啦啦啦啦 #2
    同学你好,建议同学将自己控制台中具体的报错信息贴出,是哪行的代码报出空指针的异常呐。如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
    2020-01-04 16:53:10
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师