• javaWeb学习笔记_servlet使用


    servlet主要用负责web程序中的逻辑处理,属于MVC三层结构中的C(control)层,一般来讲一次请求会对应有一个servlet类,eclipse中可以直接创建servlet类

    1.新建servlet

    2.填写Class名:

    3.设定访问路径

    4.点击完成后生成如下代码:

    @WebServlet("/Upload")
    public class Upload extends HttpServlet {
    	private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public Upload() {
            super();
            // TODO Auto-generated constructor stub
        }
    
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		response.getWriter().append("Served at: ").append(request.getContextPath());
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		doGet(request, response);
    	}
    
    }
    

     然后在doGet()方法中编写代码。

    5.session和application用如下代码获得:

    ServletContext application = this.getServletContext();
    HttpSession session = request.getSession();
    
  • 相关阅读:
    JAVA实现接口监控报警系统
    批量插入数据、自定义分页器
    django与Ajax
    ORM优化查询、choices参数
    django之查询操作及开启事务
    django之ORM字段及参数
    数据库设计
    django之模型层
    django之模板层
    django之视图层
  • 原文地址:https://www.cnblogs.com/annofyf/p/9556406.html
Copyright © 2020-2023  润新知