Spring Maven Controller找不到我的JSP页面

时间:2019-03-08 17:20:42

标签: java spring maven jsp templates

我是Spring + MVN的新手。 我现在有一个带有Controller的项目,我想与JSP页面“连接”。这是项目结构:

Project Structure

我有Web-servlet.xml,其中包含:

<beans xmlns = "http://www.springframework.org/schema/beans"
       xmlns:context = "http://www.springframework.org/schema/context"
       xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation = "
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package = "com.ms.TicketsSystem" />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property> </bean>
</beans>

和web.xml:

<web-app id = "WebApp_ID" version = "2.4"
         xmlns = "http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://java.sun.com/xml/ns/j2ee
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Form Handling</display-name>

    <servlet>
        <servlet-name>Web</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Web</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

控制器:

@Controller
public class WebController {

    @RequestMapping(value="/add")
    public String addTicket(){
        /*
        TODO
         */
        return "add";
    }
}

当我转到localhost:8080/add时显示

Error resolving template [add], template might not exist or might not be accessible by any of the configured Template Resolvers

关于我在做什么错的任何建议?

1 个答案:

答案 0 :(得分:0)

模板解析器错误建议使用Thymeleaf。除非您打算使用它,否则请尝试使用spring.thymeleaf.enabled=false

在应用程序属性文件中将其禁用