In the jsp, once you click on a category, it gets appended dynamically to the end of the bookRecommendation path, so you get /bookRecommendation/fiction or /bookRecommendation/biography, etc.
PROBLEM: after doing so, when I click another link, it just gets appended to the path, so bookRecommendation/aboutMe, when I just want it to take me to /aboutMe. Everything was working as expected, before I added the method containing the path variable to the controller.
@Controller
public class SiteController {
@RequestMapping(path="/bookRecommendations/{category}", method=RequestMethod.GET)
public String displayCategoryPage(@PathVariable String category, ModelMap model) {
List<Book> bookList = new ArrayList<>();
bookList = bookDAO.getBooksByCategory(category);
model.put("category", category);
model.put("books", bookList);
return "bookCategoryTemplate";
}
@RequestMapping("/aboutMe")
public String displayAboutMe() {
return "aboutMe";
}
}
bookRecommendations.jsp:
<div class="row">
<div class="col-md-12">
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">Go To...
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<c:forEach items="${categories}" var="category">
<li><a href="bookRecommendations/${category.name}">${category.name}</a></li>
</c:forEach>
</ul>
</div>
</div>
</div>
bookCategoryTemplate.jsp:
<div class="book-category-template">
<h1 class="book-category-header">${category}</h1>
<c:forEach items="${books}" var="book">
<h3>${book.title}</h3>
</c:forEach>
</div>
header.jsp
<header class="navbar navbar-default">
<div class="container">
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li><a href="bookRecommendations">Book Recommendations</a></li>
<li><a href="aboutMe">About Me</a></li>
<li><a href="login">Login</a>
</ul>
</div>
</div>
</header>
viewResolver.xml, if that's helpful:
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
Any ideas? Thanks!