赞
踩
《一线大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码》,点击传送门,即可获取!
}
编写业务层接口:
/**
*/
public interface UserService {
}
实现业务层接口:
public class UserServiceImpl implements UserService {
private UserDao dao = new UserDaoImpl();
}
编写表现层:
@WebServlet(“/loginServlet”)
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
/*
*/
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}
}
编写BaseServlet类,然后由其他servlet继承
public class BaseServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
// 获取请求标识
String methodName = request.getParameter(“method”);
// 获取指定类的字节码对象
Class<? extends BaseServlet> clazz = this.getClass();//这里的this指的是继承BaseServlet对象
// 通过类的字节码对象获取方法的字节码对象
Method method = clazz.getMethod(methodName, HttpServletRequest.class, HttpServletResponse.class);
// 让方法执行
method.invoke(this, request, response);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
<%@ page contentType=“text/html;charset=UTF-8” language=“java” %>
<%@taglib prefix=“c” uri=“http://java.sun.com/jsp/jstl/core” %>
×
${login_msg
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。