Reputation: 1911
I'm building a service that takes a complete url as a parameter and then processes the CSV data pointed by that url. So I want to pass the the url of the CSV file as a single parameter after my service url. The whole url I really what it to work is like following,
http://mydomain.com/myservice?CSVUrl="http://ichart.finance.yahoo.com/table.csv?s=FB&d=1&e=10&f=2014&g=d&a=4&b=18&c=2012&ignore=.csv"
I hope my Java Spring MVC controller can work in following way. The issue is, the CSVUrl string I want to pass as a parameter contains special characters and other query strings that are supposed to be kept as a whole string for the CSVUrl. In addition, the CSVUrl is supposed to be something given by users. So I don't know it in advance. It also give me difficulty to encode it before passing it in the url.
public ModelAndView processCSVFile(@RequestParam String CSVUrl) {
ModelAndView mav = new ModelAndView();
CsvDataProcessor csvDataProcessor = new CsvDataProcessor();
String vizData = csvDataProcessor.getVizDataTableString(CSVUrl);
mav.addObject("csvData", csvData);
mav.setViewName("myservice.jsp");
return mav;
}
It does not work in this way. How can I make it work? As I searched, I may need use URLEncoder and URLDecoder. But have not figured out how to make it work. Appreciate for any help in advance!
Upvotes: 1
Views: 3232
Reputation: 41123
Please have a look at URLEncoder, for example:
URLEncoder.encode("mysite.com?a=foo&b=cow", "UTF-8");
Should give you mysite.com%2Fa%3Dfoo%26b%3Dcow
Upvotes: 4