无法传递标签src属性中的参数

时间:2022-06-05 14:15:44

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. In controller a business service will take three parameters namely param1 , param2 and param3 and fetch the image from db.

情况:src属性中的url应该将控制转移到控制器。在控制器中,业务服务将采用三个参数,即param1,param2和param3,并从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了很多但我无法找到答案可以有人帮忙吗?

1 个解决方案

#1


0  

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. See: SpringMVC RequestMapping for GET parameters

至于Spring中的请求映射,您只需要为方法的每个参数添加一个@RequestParam注释。请参阅:SpringMVC RequestMapping for GET参数

#1


0  

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. See: SpringMVC RequestMapping for GET parameters

至于Spring中的请求映射,您只需要为方法的每个参数添加一个@RequestParam注释。请参阅:SpringMVC RequestMapping for GET参数