看网上的教程搭建一个ssh框架,刚开始可以,但是我后来修改struts.xml文件后就提示HTTP Status 404 - There is no Action mapped for action name umshowUser.
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SSH Project</display-name>
<filter>
<filter-name>SSH</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>SSH</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>userList.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts.xml文件在src下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="um" extends="struts-default" namespace="/um">
<action name="um*" method="{1}" class="com.hst.ssh.action.RegisterAction" >
<result name="userList" >/userList.jsp</result>
<result name="success" >/success.jsp</result>
</action>
</package>
</struts>
applicationContext.xml文件 在web-inf/lib下
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- 定义数据源的信息 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property name="jdbcUrl">
<value>jdbc:oracle:thin:@10.152.89.65:1521:orcl</value>
</property>
<property name="user">
<value>itiltest</value>
</property>
<property name="password">
<value>itiltest123</value>
</property>
<property name="maxPoolSize">
<value>80</value>
</property>
<property name="minPoolSize">
<value>1</value>
</property>
<property name="initialPoolSize">
<value>1</value>
</property>
<property name="maxIdleTime">
<value>20</value>
</property>
</bean>
<!--定义Hibernate的SessionFactory -->
<!-- SessionFactory使用的数据源为上面的数据源 -->
<!-- 指定了Hibernate的映射文件和配置信息 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>com/hst/ssh/beans/User.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="show_sql">true</prop>
<prop key="hibernate.jdbc.batch_size">20</prop>
<prop key="hibernate.connection.autocommit">false</prop>
</props>
</property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="baseDao" class="com.hst.ssh.daoImpl.UserDao">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!--用户注册业务逻辑类 -->
<bean id="userManager" class="com.hst.ssh.serviceImp.UserManagerImpl">
<property name="dao">
<ref bean="baseDao" />
</property>
</bean>
<!-- 用户注册的Action -->
<bean id="regAction" class="com.hst.ssh.action.RegisterAction">
<property name="userManager">
<ref bean="userManager" />
</property>
</bean>
<!-- more bean definitions go here -->
</beans>
action文件
package com.hst.ssh.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.hst.ssh.forms.UserForm;
import com.hst.ssh.service.UserManager;
public class RegisterAction extends ActionSupport {
private static final long serialVersionUID = 1L;
private UserForm user;
private UserManager userManager;
private HttpServletRequest request;
protected HttpServletRequest getRequest() {
return ServletActionContext.getRequest();
}
public UserForm getUser() {
return user;
}
public void setUser(UserForm user) {
this.user = user;
}
public void setUserManager(UserManager userManager) {
this.userManager = userManager;
}
public String execute() {
try {
this.userManager.regUser(user);
return SUCCESS;
} catch (Exception e) {
e.printStackTrace();
return ERROR;
}
}
public String showUser(){
List userList = this.userManager.showUserList("from T_USER_TEXT");
this.getRequest().setAttribute("userList", userList);
return "userList";
}
}
而且现在输入http://localhost:8080/shtProject/register.action能够访问到这个页面
我现在struts.xml根本没有配置register的action为什么还能访问到以前配置的action呢
之前struts.xml配置如下
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<package name="ynwi" extends="struts-default">
<action name="register" class="regAction">
<result name="input">/Register.jsp</result>
<result name="success">/Success.jsp</result>
<result name="error">/Fail.jsp</result>
</action>
</package>
</struts>
------解决思路----------------------
在myeclipse中最上面有Project======>clean,清空一下项目,最好再重新部署一下,因为tomcat里面的内容可能没有更改过来