【问题标题】:Spring ModelAndView not finding the JSP page - Requested resources is not availableSpring ModelAndView 找不到 JSP 页面 - 请求的资源不可用
【发布时间】:2013-12-29 23:44:41
【问题描述】:

我遇到了一个问题,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 veiw:

<%@ 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>

【问题讨论】:

  • 发布您的 web.xml 文件和服务器返回的包含链接的 html
  • 文件/WEB-INF/views/sso-auth-tool.jsp是否存在于您部署的webapp中?
  • 是的 /WEB-INF/views/sso-auth-tool.jsp 存在于 e=deployed webapp 中。
  • 不是您的方法view() 给出编译错误,如果orgIds==null 没有返回任何内容
  • 我认为有人在说小猪...

标签: java jsp spring-mvc


【解决方案1】:
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 时设置,而不是相反的情况。

【讨论】:

  • 试过了,没用。
  • 发布您遇到的错误以及 jsp 文件的名称是什么?
  • 找不到资源 - 404. 文件名 sso-auth-tool.jsp
猜你喜欢
  • 2016-09-21
  • 1970-01-01
  • 2016-03-14
  • 1970-01-01
  • 2019-11-18
  • 2013-01-06
  • 2014-04-13
  • 2013-02-16
  • 2012-05-16
相关资源
最近更新 更多