0

I am developing a spring mvc web app , in one of the jsp's i am trying to display image in a dialog box :

my javascript function is as follows :

 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.

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 ?

varun singhal
  • 125
  • 1
  • 8

1 Answers1

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.

You just need to build the URL in JavaScript:

$('#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

Community
  • 1
  • 1
Lee Kowalkowski
  • 11,591
  • 3
  • 40
  • 46