Struts通配符使用的坑???

以下是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>
<!-- 是否使用开发模式 -->
<constant name="struts.devMode" value="false" />
		<package name="customer" extends="struts-default" namespace="/"> 
		
		<interceptors>
			<!-- 注册拦截器 -->
			<interceptor name="loginInterceptor" class="cn.leo.interceptor.LoginInterceptor"></interceptor>
			<!-- 注册拦截器栈 -->
			<interceptor-stack name="myStack">
				<interceptor-ref name="loginInterceptor">
					<param name="excludeMethods">login</param>
				</interceptor-ref>
				<interceptor-ref name="defaultStack"></interceptor-ref>
			</interceptor-stack>
		</interceptors>
		<!-- 指定包中的默认拦截器栈 -->
		<default-interceptor-ref name="myStack"></default-interceptor-ref>
		<!-- 定义全局结果集 -->
		<global-results>
			<result name="toLogin" type="redirect" >/login.jsp</result>
		</global-results>
		<global-exception-mappings>
			<!-- 如果出现java.lang.RuntimeException异常,就将跳转到名为error的结果 -->
			<exception-mapping result="error" exception="java.lang.RuntimeException"></exception-mapping>
		</global-exception-mappings>
		
			<action name="CustomerAction_*" class="com.leo.web.CustomerAction" method="{1}" >
			 <result name="list" >/jsp/customer/list.jsp</result>
			 <result name="customer" >/jsp/customer/edit.jsp</result>
			<result name="toList" type="redirectAction">
	             <param name="actionName">CustomerAction_list</param>
	             <param name="namespace">/</param>
	         </result>
			</action>
			<action name="UserAction_login" class="com.leo.web.UserAction" method="login" >
			 <result name="toHome"  type="redirect">index.htm</result>
			</action>
		</package>
</struts>

action:
 

private Customer customer=new Customer();
	private CustomerService service=new CustomerServiceImpl();
	public String test() {
		System.out.println("test...");
		return Action.NONE;
	}
	
	public String list() throws Exception {
		//1 接受参数
		String cust_name = ServletActionContext.getRequest().getParameter("cust_name");
		//2 创建离线查询对象
		DetachedCriteria dc =DetachedCriteria.forClass(Customer.class);
		//3 判断参数拼装条件
		if(StringUtils.isNotBlank(cust_name)){
			dc.add(Restrictions.like("cust_name", "%"+cust_name+"%"));
		}
		//4 调用Service将离线对象传递
		List<Customer> list = service.getAll(dc);
		//5 将返回的list放入request域.转发到list.jsp显示
		
		//ServletActionContext.getRequest().setAttribute("list", list);
		
		// 放到ActionContext
		ActionContext.getContext().put("list", list);
		
		
		return "list";
	}


	//添加客户
	public String add() throws Exception {
		System.out.println("add方法:");
		//1 调用Service
		service.addCutomer(customer);
		//2 重定向到列表action方法
		return "toList";   
	}
	//修改客户
	public String update() throws Exception {
		System.out.println("修改");
		Customer user =service.getCustomer(customer);
		ActionContext.getContext().put("customer", user);
		return "customer";
	}
	//保存修改的客户
	public String save() {
		service.saveUpdate(customer);
		return "toList";
	}
	
	@Override
	public Customer getModel() {
		// TODO Auto-generated method stub
		return customer;
	}

但是通过调用时就是不显示:这是为什么???搞了好久没头绪请大神指明原有:

访问以下路径:http://localhost:8080/Crm/CustmoerAction_update

报错:Message There is no Action mapped for namespace [/] and action name [UserAction_login] associated with context path [/Crm].

由于使用的是struts2的2.5版本现在只需要在struts.xml中添加以下即可以实现通配字符的调用问题:

<allowed-methods>list,add</allowed-methods>这里面写的是调用的方法名放到<action></action>标签内即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kay三石 [Alay Kay]

你的鼓励是我最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值