Spring ModelAndView找不到JSP页面 - 请求的资源不可用

时间:2013-12-11 19:55:02

标签: java jsp spring-mvc

我遇到的问题是ModelAndView无法找到JSP视图

以下是控制器

@Controller
public class BasicController {
    private String GUID;

    @RequestMapping(value = "/basicLti.spr", method = RequestMethod.GET)
    public ModelAndView view(@RequestParam(value = ORG_IDS_ATTRIBUTE, required = false) String orgIds) {
        ModelAndView mav = new ModelAndView();

        String GUID="one";

        if(orgIds != null) {
            mav =  new ModelAndView("sso-auth-tool");
            mav.addObject(userId, "36bdf294-2832-4179-b9e4-b4e2148fb048");
            mav.addObject(GUID,"String");
            mav.addObject(ORG_IDS_ATTRIBUTE, "512488b9-a387-45b0-b7c6-d514d112566e");
            return mav;
        }
        System.out.println("here i am");
    }

}

我有以下jsp视图:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
</head>
<body>
    <!--[if IE]>
    <form name="formLogin" action="${ssoUrl}" method="post" target="_blank">
    <p id="message" style="visibility:hidden;">Your Starrmatica course has been opened in a new window.</p>
<![endif]-->
    <!--[if !IE]>-->

    <p>Got Message</p>


        <input type='hidden' name='iqity_id' value='${user_id}'>
        <input type="hidden" name="school_id" value="${school_id}">
        <input type="submit" name="guid_key" value="${guid_key}">
        <!-- <input type="submit" id="sas-auth-tool" value="Authenticate Resources" name="submit" /> -->
    </form>
</body>
</html>

servlet-context.xml文件

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

现在它没有找到asso.jsp - HTTP 404错误! 我的问题是; 我如何评估jsp文件?

WEB.XML

<?xml version="1.0" encoding="UTF-8"?>
<!-- Use this definition if using a Java EE 6 container This also stops Eclipse 
    from complaining that 3.0 is not a valid version <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" 
    http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> -->
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <!-- The definition of the Root Spring Container shared by all Servlets 
        and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/app/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>CXFServlet</servlet-name>
        <servlet-class>
            org.apache.cxf.transport.servlet.CXFServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>CXFServlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>*.spr</url-pattern>
    </servlet-mapping>

    <error-page>
        <exception-type>java.lang.Throwable</exception-type>
        <location>/WEB-INF/error.jsp</location>
    </error-page>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>


</web-app>

1 个答案:

答案 0 :(得分:0)

ModelAndView mav = new ModelAndView("sso-auth-tool");

    String GUID="one";

    if(orgIds != null) {
        mav.addObject(userId, "36bdf294-2832-4179-b9e4-b4e2148fb048");
        mav.addObject(GUID,"String");
        mav.addObject(ORG_IDS_ATTRIBUTE, "512488b9-a387-45b0-b7c6-d514d112566e");
        return mav;
    }
    System.out.println("here i am");

这应该有效,因为必须有一个视图名称,但在您的代码中,视图名称仅在orgIds != null不相反的情况下设置。