Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java InternalViewResolver在Spring中不工作_Java_Spring_Spring Mvc - Fatal编程技术网

Java InternalViewResolver在Spring中不工作

Java InternalViewResolver在Spring中不工作,java,spring,spring-mvc,Java,Spring,Spring Mvc,我已经创建了一个测试SpringMVC项目。此处控制器正在执行,但稍后internalview解析器无法转换逻辑名称,因为当我点击URL时,我在浏览器上获得“HTTP状态404-请求的资源()不可用”。但控制器内的SOP正在执行 Web.xml: <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="ht

我已经创建了一个测试SpringMVC项目。此处控制器正在执行,但稍后internalview解析器无法转换逻辑名称,因为当我点击URL时,我在浏览器上获得“HTTP状态404-请求的资源()不可用”。但控制器内的SOP正在执行

Web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    classpath:applicationContext.xml
    </param-value>
</context-param>    

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>


<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>spring/mvc/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

<!-- <welcome-file-list>
    <welcome-file>/WEB-INF/views/Welcome.jsp</welcome-file>
</welcome-file-list>
<session-config>
  <session-timeout>60</session-timeout>
</session-config> -->
</web-app>
servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/mvc 
                    http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                    http://www.springframework.org/schema/beans 
                    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/tx 
                    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                    http://www.springframework.org/schema/context 
                    http://www.springframework.org/schema/context/spring-context-3.1.xsd
                    http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd">


<annotation-driven />

<context:component-scan base-package="com.springmvc.prac.springmvcprac" />

    <resources mapping="/resources/**" location="/resources/" />

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

</beans:beans>

servlet-context.xml位于webapp/spring/mvc中


Welcome.jsp位于webapp/WEB-INF/view

您的配置缺少view类。改变

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


问题出在web.xml中,因为appservlet URL模式从/*更改为/

appServlet /


虽然这个问题已经解决了,但实际上我并不了解根本原因,因为之前控制器也被调用了

您要部署到哪里?您的应用程序类路径中是否存在
javax.servlet.jsp.jstl.core.Config
?我正在tomcat服务器上部署,而javax.servlet.jsp.jstl.core.Config不存在。我的JSP非常简单,它不包含任何jstl TAJS,请查看我的答案。如果
javax.servlet.jsp.jstl.core.Config
不存在,则视图类不会自动配置。即使在添加了JstlView之后,我也面临同样的问题。PSB servlet-context.xml你说的PSB是什么意思?请看下面(PSB):我正要再次添加xml的内容
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/view/" />  
    <beans:property name="suffix" value=".jsp" />
</beans:bean>
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <beans:property name="prefix" value="/WEB-INF/view/" />  
    <beans:property name="suffix" value=".jsp" />
</beans:bean>