2

I'm trying to send an ID to my controller using:

<a href="/host/admin/sensor/downloadCSV/${sensor.id}" class="btn btn-primary"> Export CSV</a>

The content of ${sensor.id} variable is: testApp_provider.osom_component2.RT3

In my controller I'm getting it with:

@RequestMapping("/downloadCSV/{sensorId}")
public ModelAndView handleRequestInternal(HttpServletResponse response, @PathVariable final String sensorId) throws IOException {
    System.out.println("sensor:"+sensorId);
    return null;
}

But the output of the println is:

sensor:testApp_provider.osom_component2

I'm losing the last part: .RT3

Any Ideas?

1 Answer 1

2

You need to change it to,

@RequestMapping("/downloadCSV/{sensorId:.+}")
public ModelAndView handleRequestInternal(HttpServletResponse response, @PathVariable final String sensorId) throws IOException {
    System.out.println("sensor:"+sensorId);
    return null;
}

As everything behind the last dot is a file extension for Spring, so it truncates it by default.

The other, global solution would be to set useRegisteredSuffixPatternMatch property to false when registering the RequestMappingHandlerMapping.

More cleaner way however is to add trailing / slash at the end

@RequestMapping("/downloadCSV/{sensorId}/")
Sign up to request clarification or add additional context in comments.

Comments

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.