很急很急,我自己研究了两天了,应该就是配置文件的问题,下面是我的配置文件,跪谢!!!
我的web.xml配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring.xml</param-value>
</context-param>
<filter>
<description>字符集过滤器</description>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<description>字符集编码</description>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<description>spring监听器</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<servlet>
<description>spring mvc servlet</description>
<servlet-name>springMvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>spring mvc 配置文件</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springMvc</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>15</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>WEB-INF/pages/info.jsp</welcome-file>
</welcome-file-list>
</web-app>
spring.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: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
">
<!-- 自动扫描(自动注入) -->
<context:component-scan base-package="com.demo.service..*,com.demo.dao..*" />
</beans>
spring-mvc配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
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/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 自动扫描controller包下的所有类,使其认为spring mvc的控制器 -->
<context:component-scan base-package="com.demo.controller" />
<!-- 避免IE执行AJAX时,返回JSON出现下载文件 -->
<bean id="mappingJacksonHttpMessageConverter"
class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-- 开启注解 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"></bean>
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/pages/" p:suffix=".jsp" >
</bean>
<!-- c3p0 有连接池作用,使用properties文件下的属性值 -->
<bean id ="dataSourceTarget" class= "com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >
</bean >
<!-- 对数据源进行代理 -->
<bean id ="proxyDataSource" class= "org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy" >
<constructor-arg >
<ref bean ="dataSourceTarget" />
</constructor-arg >
</bean >
<bean id ="transactionManager" class= "org.springframework.jdbc.datasource.DataSourceTransactionManager" >
<property name ="dataSource" ref="proxyDataSource" />
</bean >
<tx:annotation-driven transaction-manager ="transactionManager" />
<!-- 直接使用数据源的代理对象 -->
<bean id ="queryRunner" class= "org.apache.commons.dbutils.QueryRunner" >
<constructor-arg >
<ref bean ="proxyDataSource" />
</constructor-arg >
</bean >
</beans>
数据连接池用的c3p0,配置c3p0-config.xml如下
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config>
<default-config>
<property name="driverClass">net.sf.log4jdbc.DriverSpy</property>
<property name="jdbcUrl">jdbc:log4jdbc:mysql://222.28.71.331:3306/my?characterEncoding=utf8</property>
<property name="user">root</property>
<property name="password">root</property>
<property name="initialPoolSize">5</property>
<property name="maxPoolSize">10</property>
</default-config>
<!-- 配置多数据源时使用,在ComboPooledDataSource核心类中存在一个带String参数的构造函数,该构造函数当不用写时,默认读取的是default-config
当使用该参数,并且写上name-config中的name参数时,会去读取下面的这个配置文件
-->
<named-config name="oracleConfig">
<property name="driverClass">com.mysql.jdbc.Driver</property>
<property name="jdbcUrl">jdbc:mysql:///day17</property>
<property name="user">root</property>
<property name="password">root</property>
<property name="initialPoolSize">5</property>
<property name="maxPoolSize">10</property>
</named-config>
</c3p0-config>
4 个解决方案
#1
tomcat启动有没有报错?访问路径错了?
#2
<welcome-file-list>
<welcome-file>WEB-INF/pages/info.jsp</welcome-file>
</welcome-file-list>
我把这web.xml这一段去掉之后就好了,我也知道web-info目录下的文件无法直接访问,要通过映射来访问,但是之前师兄撘的spring+springMVC+mybatis的框架就是这么写的。。。
请问一下,我要设置打开项目的欢迎页是web-info下的jsp要怎么设置呢?
#3
在WEB-INF前面加个/
#4
后来我直接写成映射的形式就好了,类似于 myController/index.html这样的形式
#1
tomcat启动有没有报错?访问路径错了?
#2
tomcat启动有没有报错?访问路径错了?
<welcome-file-list>
<welcome-file>WEB-INF/pages/info.jsp</welcome-file>
</welcome-file-list>
我把这web.xml这一段去掉之后就好了,我也知道web-info目录下的文件无法直接访问,要通过映射来访问,但是之前师兄撘的spring+springMVC+mybatis的框架就是这么写的。。。
请问一下,我要设置打开项目的欢迎页是web-info下的jsp要怎么设置呢?
#3
tomcat启动有没有报错?访问路径错了?
<welcome-file-list>
<welcome-file>WEB-INF/pages/info.jsp</welcome-file>
</welcome-file-list>
我把这web.xml这一段去掉之后就好了,我也知道web-info目录下的文件无法直接访问,要通过映射来访问,但是之前师兄撘的spring+springMVC+mybatis的框架就是这么写的。。。
请问一下,我要设置打开项目的欢迎页是web-info下的jsp要怎么设置呢?
在WEB-INF前面加个/
#4
后来我直接写成映射的形式就好了,类似于 myController/index.html这样的形式