• SpringMVC两种处理器适配器


    1、实现Controller接口的处理器适配器

     1 package com.xiaostudy;
     2 
     3 import javax.servlet.http.HttpServletRequest;
     4 import javax.servlet.http.HttpServletResponse;
     5 
     6 import org.springframework.web.servlet.ModelAndView;
     7 import org.springframework.web.servlet.mvc.Controller;
     8 
     9 public class MyController implements Controller{
    10 
    11     public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    12         //创建视图
    13         ModelAndView modelAndView = new ModelAndView();
    14         
    15         //设置页面回显数据
    16         modelAndView.addObject("hello", "xiaostudy");
    17         
    18         //返回物理视图,指定跳转的视图
    19 //        mv.setViewName("/WEB-INF/index.jsp");
    20         
    21         //返回逻辑视图
    22         modelAndView.setViewName("index");
    23         
    24         return modelAndView;
    25     }
    26 
    27 }

    2、实现HttpRequestHandler接口的处理器适配器

     1 package com.xiaostudy;
     2 
     3 import java.io.IOException;
     4 
     5 import javax.servlet.ServletException;
     6 import javax.servlet.http.HttpServletRequest;
     7 import javax.servlet.http.HttpServletResponse;
     8 
     9 import org.springframework.web.HttpRequestHandler;
    10 
    11 public class HttpController implements HttpRequestHandler{
    12 
    13     @Override
    14     public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    15         request.setAttribute("hello", "xiaostudy.xiaostudy");
    16         request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
    17     }
    18 
    19 }

  • 相关阅读:
    QT常用技巧--程序延时
    python中zip()函数的用法
    numpy.random.choice(a, size = None, replace = True, p = None)用法
    Python keras.layers .ZeroPadding2D() 详解
    Socat 入门笔记
    echo命令的使用
    Type Error('keyword argument not understood: ', 'interpolation') 解决方案
    Pytorch 包下载
    双边滤波Matlab代码
    hihocoder 第170周 Word Construction (dfs+剪枝)
  • 原文地址:https://www.cnblogs.com/xiaostudy/p/9594452.html
Copyright © 2020-2023  润新知