Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringJSP-如何显示请求值?_Java_Spring Mvc - Fatal编程技术网

Java SpringJSP-如何显示请求值?

Java SpringJSP-如何显示请求值?,java,spring-mvc,Java,Spring Mvc,我想回显请求中选择的缓存操作,以便它显示在浏览器上。我几乎没有JSP经验。如何获得要显示的操作的值 JSP: 缓存操作结果-${Operation} ${nextObject.toString()} 控制器代码段: ${param['operation']} @RequestMapping(value=“/objectcache”,method=RequestMethod.GET) 公共ModelAndView对象缓存(@RequestParam(“操作”)字符串操作,HttpSer

我想回显请求中选择的缓存操作,以便它显示在浏览器上。我几乎没有JSP经验。如何获得要显示的操作的值

JSP:


缓存操作结果-${Operation}
    ${nextObject.toString()}
控制器代码段:

${param['operation']} 
@RequestMapping(value=“/objectcache”,method=RequestMethod.GET)
公共ModelAndView对象缓存(@RequestParam(“操作”)字符串操作,HttpServletRequest请求){
List cacheReturnValue=new ArrayList();
ModelAndView mav=newmodelandview(“/utils/objectCache”,“results”,cacheReturnValue);
if(operation.equalsIgnoreCase(“重载”)){
cacheReturnValue=this.reloadCache();
}
mav.addObject(“操作”,操作);
返回新的ModelAndView(“/utils/objectCache”,“results”,cacheReturnValue);
}

JSP页面可以通过表达式访问多个。根据该文档中给出的示例,您可以获得如下参数值:

@RequestMapping(value = "/objectcache", method = RequestMethod.GET)
public ModelAndView objectCache(@RequestParam("operation") String operation,
        HttpServletRequest req) {

    List<String> cacheReturnValue = new ArrayList<String>();

    if (operation.equalsIgnoreCase("reload")) {
        cacheReturnValue = this.reloadCache();
    }

    ModelAndView mav = new ModelAndView("/utils/objectCache");
    mav.addObject("results", cacheReturnValue);
    mav.addObject("operation", operation);
    return mav;
}
删除错误后,you have code应能正常工作-您已经创建了两次
ModelAndView
,因此忽略了添加到第一个
ModelAndView
对象的“操作”。解决方案-仅创建一次mav

return new ModelAndView("/utils/objectCache")
        .addObject("results", cacheReturnValue)
        .addObject("operation", operation);
@RequestMapping(value = "/objectcache", method = RequestMethod.GET)
public ModelAndView objectCache(@RequestParam("operation") String operation,
        HttpServletRequest req) {

    List<String> cacheReturnValue = new ArrayList<String>();

    if (operation.equalsIgnoreCase("reload")) {
        cacheReturnValue = this.reloadCache();
    }

    ModelAndView mav = new ModelAndView("/utils/objectCache");
    mav.addObject("results", cacheReturnValue);
    mav.addObject("operation", operation);
    return mav;
}
return new ModelAndView("/utils/objectCache")
        .addObject("results", cacheReturnValue)
        .addObject("operation", operation);