春天渲染欢迎文件像文本

时间:2016-05-02 02:08:53

标签: java spring maven spring-mvc

我是春天新手,我的问题是index.jsp让我喜欢文字。 这是我的web.xml 我使用netbeans,spring 4,glassfish和maven

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>

</web-app>

弹簧servlet.xml中

       <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd 
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd
">
    <mvc:default-servlet-handler/>
    <context:annotation-config />
    <mvc:annotation-driven />
    <mvc:resources mapping="/images/**" location="/images/" />
    <mvc:resources mapping="/css/**" location="/css/" />
    <mvc:resources mapping="/bootstrap/**" location="/resources/" />
    <mvc:resources mapping="/js/**" location="/js/" />    
    <context:component-scan base-package="mx.com.shopping.cart.spring.controller" />
    <bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
</beans>

my tree directory 但是表明 browser

1 个答案:

答案 0 :(得分:0)

让您的春季调度员映射您的网址。因此,在您的web.xml中,将您的welcome文件更改为:

<welcome-file>/</welcome-file>

然后在你的控制器中添加索引的映射。

@RequestMapping(value = "/", method = RequestMethod.GET)
public String viewIndex() {
   return "index";
}

将index.jsp放入WEB-INF / jsp文件夹