I would like to pass 4 parameter from view. It looks like this-
<button>
<a href="/generateDetails/${fromDate}/${toDate}/${shopList.shopId}/${billStatus}" target="_blank" title="Download">Download</a>
</button>
In controller
@RequestMapping(value = "generateDetails/{what to do here}", method = RequestMethod.GET)
private void generateDetails(
HttpServletRequest request, HttpServletResponse response,
@PathVariable("what to do here") String something) {
//Codes for generate pdf report
}
Please provide me some details about corrections in View and Controller end.
I have tried:
In View End-
<button>
<a href="/generateDetails/${fromDate}/${toDate}/${shopList.shopId}/${billStatus}" target="_blank" title="Download">Download</a>
</button>
In Controller-
@RequestMapping(value = "generateDetails/{fromDate}/{toDate}/{shopId}/{billStatus}", method = RequestMethod.GET)
private void generateDetails(
HttpServletRequest request, HttpServletResponse response,
@PathVariable("fromDate") String fDate,
@PathVariable("toDate") String tDate,
@PathVariable("shopId") String shopId,
@PathVariable("billStatus") String bStatus) {
//Codes for generate pdf report
}
In view end, after clicking the button it is not working. If i pass single parameter then the button works and controller gets the value.
I would like to pass 4 parameter from view. It looks like this-
<button>
<a href="/generateDetails/${fromDate}/${toDate}/${shopList.shopId}/${billStatus}" target="_blank" title="Download">Download</a>
</button>
In controller
@RequestMapping(value = "generateDetails/{what to do here}", method = RequestMethod.GET)
private void generateDetails(
HttpServletRequest request, HttpServletResponse response,
@PathVariable("what to do here") String something) {
//Codes for generate pdf report
}
Please provide me some details about corrections in View and Controller end.
I have tried:
In View End-
<button>
<a href="/generateDetails/${fromDate}/${toDate}/${shopList.shopId}/${billStatus}" target="_blank" title="Download">Download</a>
</button>
In Controller-
@RequestMapping(value = "generateDetails/{fromDate}/{toDate}/{shopId}/{billStatus}", method = RequestMethod.GET)
private void generateDetails(
HttpServletRequest request, HttpServletResponse response,
@PathVariable("fromDate") String fDate,
@PathVariable("toDate") String tDate,
@PathVariable("shopId") String shopId,
@PathVariable("billStatus") String bStatus) {
//Codes for generate pdf report
}
In view end, after clicking the button it is not working. If i pass single parameter then the button works and controller gets the value.
Share edited Mar 5 at 16:13 Doug Breaux 5,1051 gold badge27 silver badges68 bronze badges asked Mar 4 at 8:28 R1f4tR1f4t 11 bronze badge 3 |1 Answer
Reset to default 0In view
<button onclick="downloadReport()">Download</button>
<script>
function downloadReport() {
let fromDate = encodeURIComponent('${fromDate}');
let toDate = encodeURIComponent('${toDate}');
let shopId = encodeURIComponent('${shopList.shopId}');
let billStatus = encodeURIComponent('${billStatus}');
window.open(`/generateDetails/${fromDate}/${toDate}/${shopId}/${billStatus}`, '_blank');
}
</script>
in Controller
@RequestMapping(value = "/generateDetails/{fromDate}/{toDate}/{shopId}/{billStatus}", method = RequestMethod.GET)
private void generateDetails(
HttpServletRequest request,
HttpServletResponse response,
@PathVariable("fromDate") String fromDate,
@PathVariable("toDate") String toDate,
@PathVariable("shopId") String shopId,
@PathVariable("billStatus") String billStatus
) {
//Codes for generate pdf report
}
for more security and prevent some issues it's good to use Query Parameters instead path variables
<input>
tag within the<form>
tag where i usedformaction
attribute to redirect to the URL in View end. And in Controller end i used@ModelAttribute
annotation to get each of the inputted form data. It's working just fine :) – R1f4t Commented Mar 11 at 8:15