【问题标题】:Spring Maven Controller can't find my JSP pagesSpring Maven Controller 找不到我的 JSP 页面
【发布时间】:2019-03-08 17:20:42
【问题描述】:

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

我有 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

关于我做错了什么有什么建议吗?

【问题讨论】:

    标签: java spring maven jsp templates


    【解决方案1】:

    模板解析器错误建议使用 Thymeleaf。除非您打算使用它,否则请尝试在您的应用程序属性文件中使用 spring.thymeleaf.enabled=false 禁用它

    【讨论】:

    • 感谢您的建议! :) 当我在家时,我会尝试这样做。如果它有效,我会通知你。
    猜你喜欢
    • 2014-11-15
    • 2020-03-08
    • 1970-01-01
    • 2018-09-05
    • 2015-02-05
    • 1970-01-01
    • 2019-12-29
    • 1970-01-01
    • 2013-12-29
    相关资源
    最近更新 更多