项目在tomcat部署成功,运行却报404错误,把所有文件复制到一个新的项目却能运行,后来又开始404.。。。

时间:2021-05-05 20:07:10

ssm项目在tomcat部署成功,运行却报404错误,把所有文件复制到一个新的项目却能运行,后来又开始404,求解!配置xml如下:

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/j2ee" xmlns:javaee="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/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
  <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>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:springmvc-servlet.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>userlogin.jsp</welcome-file>
  </welcome-file-list>
</web-app>

applicationContext.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"
	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-4.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">

	<!-- 加载classpath下的db.properties文件 -->
	<!-- <context:property-placeholder location="db.properties" /> -->
	<bean id="propertyConfigurer"
		class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
		<!--<property name="location" value="classpath:jdbc.properties" /> -->
		<property name="locations">
			<list>
				<!-- 属性文件加载列表 -->
				<value>classpath:db.properties</value>
			</list>
		</property>
	</bean>

	<!--第一步: 配置dataSource -->
	<bean id="dataSource" class="${dataSource}" destroy-method="close">
		<property name="driverClassName" value="${jdbc.driver}" />
		<property name="url" value="${jdbc.url}" />
		<property name="username" value="${jdbc.username}" />
		<property name="password" value="${jdbc.password}" />
		<!-- 初始化连接大小 -->
		<property name="initialSize" value="${initialSize}"></property>
		<!-- 连接池最大数量 -->
		<property name="maxActive" value="${maxActive}"></property>
		<!-- 连接池最大空闲 -->
		<property name="maxIdle" value="${maxIdle}"></property>
		<!-- 连接池最小空闲 -->
		<property name="minIdle" value="${minIdle}"></property>
		<!-- 获取连接最大等待时间 -->
		<property name="maxWait" value="${maxWait}"></property>
	</bean>

	<!--第二步:配置sqlSessionFactory,SqlSessionFactoryBean是用来产生sqlSessionFactory的 -->
	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
		<!-- 加载数据源,使用上面配置好的数据源 -->
		<property name="dataSource" ref="dataSource" />
		<!-- 自动扫描mapping.xml文件 -->
		<property name="mapperLocations" value="classpath:com/mo/ssm/mapper/*.xml"></property>
	</bean>

	<!--配置mybatis接口代理开发 : 1、接口类名和映射文件必须同名 2、接口类和映射文件必须在同一个目录下 3、 映射文件namespace名字必须是接口的全类路径名 
		4、接口的方法名必须和映射Statement的id一致 -->
	<!-- 扫描DAO组件 -->
	<!-- MapperScannerConfigurer可以扫描指定包下的 指定接口,然后自动的实现这些接口。 -->
	<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
		<!-- 指定扫描的包名 -->
		<property name="basePackage" value="com.mo.ssm.mapper" />
		<!-- 通过注解来指定扫描的接口,即当配置了该 注解以后,MapperScannerConfigurer会扫描 包下带有该注解的接口。 该注解需要自定义,当配置它时会扫描带有 
			注解的接口,不配置时会扫描所有的接口。 -->
		<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
	</bean>

	<!-- 开启IOC注解扫描 属于spring范围 -->
	<context:component-scan base-package="com.mo.ssm.*" />

	<!-- 第三步:配置事务管理 -->
	<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource" />
	</bean>

	<!-- 配置通知 -->
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="add*" propagation="REQUIRED" />
			<tx:method name="append*" propagation="REQUIRED" />
			<tx:method name="insert*" propagation="REQUIRED" />
			<tx:method name="save*" propagation="REQUIRED" />
			<tx:method name="update*" propagation="REQUIRED" />
			<tx:method name="modify*" propagation="REQUIRED" />
			<tx:method name="edit*" propagation="REQUIRED" />
			<tx:method name="delete*" propagation="REQUIRED" />
			<tx:method name="remove*" propagation="REQUIRED" />
			<tx:method name="repair" propagation="REQUIRED" />
			<tx:method name="delAndRepair" propagation="REQUIRED" />

			<tx:method name="get*" propagation="SUPPORTS" />
			<tx:method name="find*" propagation="SUPPORTS" />
			<tx:method name="load*" propagation="SUPPORTS" />
			<tx:method name="search*" propagation="SUPPORTS" />
			<tx:method name="datagrid*" propagation="SUPPORTS" />

			<tx:method name="*" propagation="SUPPORTS" />
		</tx:attributes>
	</tx:advice>

	<!-- 配置拦截service -->
	<aop:config>
		<aop:advisor advice-ref="txAdvice"
			pointcut="execution(* com.mo.ssm.service.*.*(..))" />
	</aop:config>
</beans>

springmvc-servlet.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:mvc="http://www.springframework.org/schema/mvc"
  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-3.2.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.2.xsd 
    http://www.springframework.org/schema/aop 
    http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
    http://www.springframework.org/schema/tx 
    http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
    
    <!-- 注解方式 -->
    <mvc:annotation-driven />
  <!-- 文件扫描 -->
  <context:component-scan base-package="com.mo.ssm.controller"></context:component-scan>
 
  <!-- annotation-driven:默认创建了多个对象:RequestMappingHandlerMapping,RequestMappingHandlerAdapter
    也就提供对json格式支持
   -->
  <mvc:annotation-driven/>
  <!-- 视图解析器 -->
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/" />
    <property name="suffix" value=".jsp" />
  </bean>
</beans>

jsp登录页面:

  <body>
    	登录首页<br>
    <form action="login" method="get">
             用户名<input id="username" type="text"/><br/>
             密码<input id="password" type="password"/><br/>  
    <input id="loginsubmit" type="submit" value="登录"/> 
    <input type="reset" value="重置"><br/>       
    </form>
  </body>
 controller页面:
package com.mo.ssm.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.mo.ssm.entity.Rtuusertab;
import com.mo.ssm.service.RtuusertabService;

@Controller
public class RtuusertabController {

	@Resource
	private RtuusertabService rService;
	
	@RequestMapping(value="/login.do",method=RequestMethod.GET)
	public ModelAndView login(String username,String password) {
		Rtuusertab rtuusertab=rService.findNameAndPass(username, password);
		if (null!=rtuusertab) {
			ModelAndView mView=new ModelAndView("list");
			return mView;
		}
		return new ModelAndView("userlogin");
	}
}