我在使用springMVC+tomcat写一个项目,但是我在访问我的jsp页面时,在浏览器中显示为源码:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="flysky" prefix="flysky"%>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=100">
<title>酒店订阅服务</title></head>
<body>
<div>
<form action='/HostelBed/html/hotelBed/getRS' method="post" name="form1">
PageNumber:<input type="text" name="pageNumber" id="pageNumber" value="" /><br/>
CheckInDate:<input type="text" name="checkInDate" id="checkInDate" value="" /><br/>
CheckOutDate:<input type="text" name="checkOutDate" id="checkOutDate" value="" /><br/>
Destination:<input type="text" name="destination" id="destination" value="" /><br/>
RoomCount:<input type="text" name="roomCount" id="roomCount" value="" /><br/>
AdultCount:<input type="text" name="adultCount" id="adultCount" value="" /><br/>
ChildCount:<input type="text" name="childCount" id="childCount" value="" /><br/>
<input type="submit" name="" id="" value="submit" />
</form>
</div>
</body>
</html>
但是我访问html页面的时候他又是好的!所以我可以肯定是服务器端的问题。
我的web.xml配置如下:
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/springmvc/*.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

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

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

<!-- 日志log4j的配置 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>600000</param-value>
</context-param>
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>javass.webapp.root</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>

<!-- springMVC的编码配置 -->
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>/html/hotelBed.jsp</welcome-file>
</welcome-file-list>

<jsp-config>
<taglib>
<taglib-uri>flysky</taglib-uri>
<taglib-location>/WEB-INF/tld/flysky.tld</taglib-location>
</taglib>
</jsp-config>
我的springmvc的配置文件是:<context:component-scan base-package="com.hostel.flysky"/>

<mvc:annotation-driven/>

<mvc:default-servlet-handler/>
<!-- <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/> -->

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/html"/>
<property name="suffix" value=".jsp"/>
</bean>
我怀疑是不是因为springmvc有什么东西没有配置导致的,还是我的tomcat有问题,请指教!springmvcjsp源码无法解析

解决方案 »

  1.   

    我对springmvc配置也不是很懂,但是我遇到的项目中的这个配置<property name="prefix" value="/html"/>中的value=“/”,我不知道有没有影响。prefix 、suffix这两个配置是不是有问题啊?
      

  2.   

    <property name="prefix" value="/html/"/>
      

  3.   

    +1
    另外,如果还不行的话,试试:
     InternalResourceViewResolver bean 标签下加上:
    <property name="contentType" value="text/html;charset=UTF-8" />
      

  4.   

     <servlet-mapping>
            <servlet-name>springmvc</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>
    我找到我的问题所在了,要把这里的”/*“换成.do就可以了,或者在家一段配置用来配置静态资源的访问,就可以了
    具体的原因我还没有找到,但我想应该是这些的静态资源的配置出现的了问题,谢谢各位的解答。