Reputation: 3774
Here is the code for my controller class:
package edu.byu.cio.test.web.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
@RequestMapping(value = "/")
public String helloWorld() {
System.out.println("HomeController: Passing through...");
return "WEB-INF/views/home.jsp";
}
@RequestMapping(value="/name/{Name}", method = RequestMethod.GET)
public String compare(@PathVariable("Name") String Name) {
return "WEB-INF/views/home.jsp";
}
}
I am interested in calling the second method.
When i do the get request as:
http://localhost:8081/mvc-basic/name/somename
Note:I have configured it to listen at port 8081.
I get the following error:
HTTP Status 404 - /mvc-basic/name/WEB-INF/views/home.jsp
--------------------------------------------------------------------------------
type Status report
message /mvc-basic/name/WEB-INF/views/home.jsp
description The requested resource (/mvc-basic/name/WEB-INF/views/home.jsp) is not available.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.26
I think the URI pattern is right yet I am wondering why is it showing this error. Do you find any errors in the above code? I appreciate your help.
Upvotes: 0
Views: 639
Reputation: 26
I faced this problem when I first worked on Spring Source Tool suite. After so much of struggle i figured out it to be problem with the controller class is not latest.
When i first wrote similar piece of code i did not use URI template variable and deployed it on the tc server. later I added URI template and re published/ restarted server many times thinking the controller class would have been built automatically.
Later I found that I am running the project with 'Build Automatically' unchecked on 'project' menu.
please make sure you check 'Build Automatically' if you use STS or any eclipse based tools and make sure u deploy latest Controller class.
Upvotes: 1
Reputation: 871
You need to post your viewResolver bean from your *-servlet.xml context file to be sure, but chances are your view resolver has a ".jsp" suffix defined, which means you don't need to specify it. The root directory for your JSPs will also be defaulting to /WEB-INF.
Instead of returning "WEB-INF/views/home.jsp" in your controller, try returning "views/home".
Upvotes: 0