web.xml是项目的配置文件:
“user”作为桥梁,联通了路径(/user)和功能实现类 com.chl.webTwo.UserServlet)
上述代码必须在
在实现类中,重写doGet和doPost方法时,要注意:
不要调用父类的方法,否则在使用post请求时,会error:405,此方法不支持get.
实现类与JSP的参数交互:
实现类:req.setAttribute(“键”,”值”)
JSP:reques.getAttribute(“键”)。在条件语句下,参数交互,JSP里要主要判null处理
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPE html><html><head><meta charset="UTF-8"><title>Insert title here</title><style type="text/css">.showmsg{color: red;}</style></head><body><form action="user?operator=login" method="post"><div><input type="text" placeholder="请输入用户名" name="username"></div><div><input type="password" placeholder="请输入用户密码" name="userpwd"></div><div><input type="submit" value="用户登录"></div><%if(null!=request.getAttribute("errormsg")){%><span class="showmsg"><%=request.getAttribute("errormsg").toString() %></span><%} %></form></body></html>
