Rakesh
Rakesh

Reputation: 221

Spring MVC Request Mapping, dealing with inherited urls

I am trying to learn Spring MVC. As part of my practice I am using below resource mappings.

Case1

@RequestMapping("/training") public String training(){ return "training"; }

Case2

@RequestMapping("/services/training") public String training(){ return "training"; }

This is the content of my jsp page. <img alt="Bootstrap Image Preview" src="./resources/images/toplogo.png">. In case 1 it is working fine, but it is expected to be <img alt="Bootstrap Image Preview" src="../resources/images/toplogo.png"> in case 2(One extra . in url). I know that this is for accessing the file, but as i want to use this in my template for spring-tiles integration, my expectation is for both type of urls it has to work. Can someone please help me how to achieve this!

Upvotes: 0

Views: 58

Answers (1)

Iker Obregon Reigosa
Iker Obregon Reigosa

Reputation: 243

You should use: spring:url

<spring:url var="url" value="/resources/images/toplogo.png">
<img alt="Bootstrap Image Preview" src="${url}"/>

This should work.

Upvotes: 1

Related Questions