1

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!

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer. But it requires I know the passed url in advance, right? What if I don't know it in advance?
Then you can pass a variable containing the user input

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.