Firstly, thank you for your time! I'm a 100% beginner on Spring MVC, and I got a feeling that this problem is caused by some stupid mistakes. I'm trying to build a RESTful Web Service. I followed the instructions from spring.io and made the "hello project" (http://localhost:8080/greeting) works.
However, when I was trying to let spring mvc resolve one of my view (.jsp). It's said
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Mar 25 01:31:04 EDT 2015 There was an unexpected error (type=Not Found, status=404). No message available
I'm not sure why this always happens, because I already have a config file as below.
@Configuration
@EnableWebMvc
@ComponentScan(basePackages="config")
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
The whole directory tree of my project is:
src-main|- java |- config |- WebConfig.java
|- hello |- Application.java
|- Greeting.java
|- GreetingController.java
|- PMethodController.java
|- webapp |- WEB-INF |- views |- pmethod.jsp
|- web.xml
I copied the web.xml from my friends. This file works fine on his project.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://ift.tt/nSRXKP"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:schemaLocation="http://ift.tt/nSRXKP http://ift.tt/LU8AHS">
<servlet>
<servlet-name>mvc-Dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>config</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>mvc-Dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>/</welcome-file>
</welcome-file-list>
</web-app>
and my PMethodController.java:
@Controller
public class PMethodController{
@RequestMapping("/method1")
public String handleRequest() {
return "pmethod";
}
}
My Application.java
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Depends on all above, If I run the project and then type http://localhost:8080/method1 It will show me the Whitelabel Error Page at the top of the page.
Thank you again for your time!
Aucun commentaire:
Enregistrer un commentaire