简体   繁体   English

无法传递参数 <img> 标签src属性

[英]unable to pass parameters in <img> tag src attribute

I am developing a spring mvc web app , in one of the jsp's i am trying to display image in a dialog box : 我正在开发一个spring mvc Web应用程序,在jsp之一中,我试图在对话框中显示图像:

my javascript function is as follows : 我的javascript函数如下:

 function displayImageData(param1,param2,param3)
     {

         $('#dialog-image-data-div').dialog({
            modal:true,
            width: 1200, 
            height: "auto" ,
            resizable:false,
            autoOpen : false,
            position: ['center',70],//used for positioning the dialog   
        });//end of dialog method

         $('#dialog-image-data-div').dialog("open");
         $('#dialog-image-data-div').html(' <img src="fetchImageData?param1=${param1}"/> ');

     }

Situation: The url in src attribute should divert control to a controller. 情况: src属性中的url应该将控制权转移给控制器。 In controller a business service will take three parameters namely param1 , param2 and param3 and fetch the image from db. 在控制器中,业务服务将采用三个参数,即param1param2param3并从db获取图像。

Problem : My problem is i am not able to pass these three paramters in the url specified in src attribute and i also dont know what the RequestMapping of the method in controller will look like , i gave googled a lot but i am not able to find answers can anyone help ? 问题:我的问题是我无法在src属性中指定的url中传递这三个参数,而且我也不知道控制器中方法的RequestMapping会是什么样,我给Google做了很多搜索,但是找不到有人可以提供答案吗?

displayImageData will be called by the browser, the value of the parameters are not known to your JSP so it will not be able to use JSTL Expression Language ${param1} to put them into your JavaScript string. displayImageData将由浏览器调用,您的JSP未知参数的值,因此它将无法使用JSTL表达式语言${param1}将其放入JavaScript字符串。

You just need to build the URL in JavaScript: 您只需要用JavaScript构建URL:

$('#dialog-image-data-div').html(' <img src="fetchImageData?param1='+param1+'&amp;param2='+param2+'&amp;param3='+param3+"/> ');

As for the request mappings in Spring, you just need to add a @RequestParam annotation for each parameter to your method. 至于Spring中的请求映射,您只需要为方法中的每个参数添加一个@RequestParam批注。 See: SpringMVC RequestMapping for GET parameters 参见: SpringMVC RequestMapping获取GET参数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM