Reputation: 23
I want to append a dynamic path in JSTL C:URL value. Below i declared a anchor tag
<a href="" id="intentCsv" class="btn add-intent" role="button">
This is my jquery code.
I am trying to append href value dynamically in above anchor tag:-
var url = "urlPath";
$('#intentCsv').attr("href", "<c:url value='csv/downloadIntentCSV/"+${url}+"' />");
But it's giving me an error that:-
"Uncaught ReferenceError: Invalid left-hand side in assignment"
On clicking anchor tag I want to invoke below method and print the url inside the method.
@Controller
@RequestMapping("/csv")
public class CSVUploadController {
@RequestMapping(value="/downloadIntentCSV/{url}")
public Object downloadIntentCSV(@PathVariable String url)
{
System.out.println("Inside Mehtod"+url);
//some code
}
}
Upvotes: 0
Views: 1581
Reputation: 2493
If you are using MVC
<a href="<c:url value="/csv/downloadIntentCSV/${YOURDYNAMICVALUE}"/>" >hello</a>
In the controller follow these
@RequestMapping(value = "/downloadIntentCSV/{YOURDYNAMICVALUE}", method =RequestMethod.GET)
public String Controller(@PathVariable("YOURDYNAMICVALUE") String YOURDYNAMICVALUE) {
...
}
or you can just send like
<a href="/csv/downloadIntentCSV?id=${urlvalue}"></a>
in the controller
@RequestMapping(value="/downloadIntentCSV/{id}",method=RequestMethod.GET)
public String Controller(@PathVariable("id") String url) {
...
}
Upvotes: 1