vlad halmer
vlad halmer

Reputation: 1301

Image not getting displayed when using path variable in spring mvc application

I am trying to show background image in my Spring mvc app. Now, the image is getting displayed in my home page but when I click a link which points to same page with some parameter appended to the url, the image is not appearing.

I am using this tag for displaying image:

       <img src="./resources/css/welcome.png" id="bg" alt="">

In my application context,

       <mvc:resources mapping="/resources/**" location="/resources/" />

Now, in my home page, if I click a link

       <a href="http://localhost:8080/chatbooster/welcome/mycategory">MyLink</a>

Image is not coming. The page name is welcome.jsp. Its controller is :

   @Controller
    public class WelcomeController  {

@RequestMapping(value = "/welcome/{category}", method = RequestMethod.GET)
public String showPage(Model modelMap, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {

        return "welcome";
    } catch (Exception exception) {

    }
}

@RequestMapping(value = "/welcome", method = RequestMethod.GET)
public String showPage1(Model modelMap, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    try {

        return "welcome";
    } catch (Exception exception) {

    }
}

 }

I am not able to understand if the image is coming when there is not path variable in welcome.html url, why it is not being loaded when I click MyLink which appends path variable in the url? Please help me out here..

Upvotes: 1

Views: 613

Answers (1)

NimChimpsky
NimChimpsky

Reputation: 47280

Use jstl tags core lib and c:URL to create the image src definition.

Upvotes: 2

Related Questions