笔记:
JSP的概述
什么是JSP
JSP:javaServer Pagss(java服务器页面),其实就是在HTML中嵌入java代码
为什么学习JSP
Servlet的缺点:
Servlet需要进行配置,不方便维护
Servlet很难向网页中输出HTML页面内容
JSP开发模式
JSP+Servlet+javaBean称为是MVC开发模式(思想)
MVC:
M:Model(模型层)
V:View(视图层)
C:Controller(控制层)
请求--->Servlet(控制层)--->JavaBean(Model)--->JSP(View).
public class LoginServlet extends HttpServlet{
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws Servlet
request.setCharacterEncoding("UTF-8");
String username=request.getParameter("username");
username=request.getParameter("password");
User user=new User();
user.setUsername(username);
user.setPassword(password);
UserModel userModel=new UserModel();
user existUser=userModel.login(user);
if(existUser==null){
request.setAttribute("msg","用户名或密码错误!");
request.getRequestDisptcher("/login.jsp").forward(request,response);
}else{
response.sendRedirect("/web02_login/success.jsp");
}
}