从Spring控制器中的HttpServletRequest读取对象

时间:2015-11-19 06:37:05

标签: java json spring jsp spring-mvc

我正在向我的弹簧控制器发送类对象。但是HttpServletRequest只接受String而不是object.Here是我的代码

download.jsp

<a class="download_excel view_download" >Download Full Excel</a>
<input type="hidden" class="result-object" value="${ReportDetails}" />

<script>

    $(document).ready(function() 
        {
            $('.view_download').click(function()
            {
                var object = $('.result-object').val();
                window.location.href =   "excelDownload.html?data="+object;     
            });
        });

    Controller file: HomeController.java

    @RequestMapping(value="/excelDownload", method = RequestMethod.GET)
    private ModelAndView excelDownload(HttpServletRequest request)
    {
        String result = request.getParameter("data");
        return null;
    }

</script>

但是我需要来自HttpServletResquest的以下QueryResult对象而不是字符串。

    QueryResult result = request.getParameter("data");

帮帮我。谢谢。

1 个答案:

答案 0 :(得分:0)

我认为你可以帮助你解决这个问题。 改变这个

  @RequestMapping(value="/excelDownload", method = RequestMethod.GET)
   private ModelAndView excelDownload(HttpServletRequest request)
   {

      @RequestMapping(value="/excelDownload", method = RequestMethod.GET)
       private ModelAndView excelDownload(HttpServletRequest         
        request,@RequestParam YourObject     
        object)
   {  .....}