为什么报错
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
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星