,我想返回的.html頁面,但是當我創建一個使用彈簧工具我的春天MVC項目套件默認情況下被使用創建.jsp頁面。的DispatcherServlet不返回html的網頁,但它可以返回的.jsp我創建一個簡單的Spring MVC aplication
當我嘗試去html的網頁它給了我這個錯誤
No mapping found for HTTP request with URI [/app/WEB-INF/views/test.html] in DispatcherServlet with name 'appServlet'
但是當我去的.jsp頁面它工作正常。
這是我的控制器類:
package com.abc.app;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate);
return "home.jsp";
}
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(Model model) {
logger.info("prueba html");
return "test.html";
}
@RequestMapping(value = "/test2", method = RequestMethod.GET)
public String test2(Model model) {
logger.info("prueba html");
return "test2.jsp";
}
}
這是MYE的servlet上下文的XML:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value="" />
</beans:bean>
<context:component-scan base-package="com.abc.app" />
</beans:beans>
這是URI我如何嘗試存取權限的網頁:
http://localhost:8080/app/test2 <--- this is the .jsp page and it works
http://localhost:8080/app/test <--- this is the .html page and it dont work it gives me this error WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/WEB-INF/views/test.html] in DispatcherServlet with name 'appServlet'
檢查此鏈接:http://stackoverflow.com/questions/20564336/internalresourceviewresolver-to-resolve-both-jsp-and-html-together –
我有我的問題相同的代碼,但仍然沒有工作,但在該人說它的作品的鏈接,爲什麼這項工作對某些人和其他人不?我不發表我的根XML怎麼一回事,因爲我認爲這不什麼都沒有做與此錯誤 – stackUser2000