Spring MVC没有渲染jsp - 配置问题?

时间:2018-01-03 01:09:33

标签: jsp spring-mvc

我知道有几页提出了类似的问题,但我已经尝试了所有我能想到的事情,并且已经完成了所有的建议,但我仍然遇到了麻烦。我只是想让Spring MVC渲染basic.jsp,虽然它打印出“In Home”语句,但它不会渲染jsp文件。根据一些建议,我尝试添加一个jsp servlet-dispatcher(现已注释掉)和mvc:default-servlet-handler和welcome-file-list但我仍然遇到同样的错误:/我真的很感激任何建议或指导!!我将永远感激不尽

indexController的:

package base;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/")
public class IndexController {

    @RequestMapping(method = RequestMethod.GET)
    public String getIndexPage(){
    System.out.println("IN HOME");
        return "basic";
    }
}

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:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="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 http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:component-scan base-package="base"/>
    <mvc:annotation-driven/> 
    <mvc:default-servlet-handler default-servlet-name="dispatcher" />
    <mvc:resources location="/WEB-INF/view/" mapping="/WEB-INF/view/**"/>

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

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" id="WebApp_ID"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <display-name>gold</display-name>
    <!-- <servlet>
        <servlet-name>jsp</servlet-name>
        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>/WEB-INF/views/*</url-pattern>
    </servlet-mapping> -->
    <servlet> 
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servlet.xml</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <welcome-file-list>  
        <welcome-file>main.jsp</welcome-file>  
        <welcome-file>basic.jsp</welcome-file>  
    </welcome-file-list>  

</web-app> 

项目结构:

GAtt
  src
    base
      IndexController.java
  Maven Dependencies
  JRE System Library
  build
  target
  WebContent
    META-INF
    static
    WEB-INF
      views
        basic.jsp
      servlet.xml
      web.xml
  pom.xml

0 个答案:

没有答案