之前看了一些struts2的視頻。
現在復習了下 struts2.發現了這個問題
網上的說的解決辦法大都沒提到這個問題,1%的文章提到了新版本的struts中 method的問題
There is no Action mapped for namespace / and action name XXX
http://localhost:8080/Struts2Learn/loginAction_login.action
原因不詳。
解決辦法:
通配符 * 的使用方法中。
struts-2.5.10.1版本下,struts.xml中 action 的配置里面 不需要指定method 屬性
struts.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <!DOCTYPE struts 4 PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" 5 "http://struts.apache.org/dtds/struts-2.5.dtd" > 6 <struts> 7 <package name="user" namespace="/" extends="struts-default"> 8 <action name="loginAction_*" class="com.learn.LoginAction" method={1}> <!--不需要method={1}--> 9 <result name="success">/loginSuccess.jsp</result> 10 <result name="fail">/loginFail.jsp</result> 11 </action> 12 </package> 13 </struts>
com.learn.LoginAction
1 package com.learn; 2 3 import com.opensymphony.xwork2.ActionSupport; 4 5 public class LoginAction extends ActionSupport { 6 7 private static final long serialVersionUID = 1L; 8 private String username; 9 private String password; 10 11 public String getUsername() { 12 return username; 13 } 14 15 public void setUsername(String username) { 16 this.username = username; 17 } 18 19 public String getPassword() { 20 return password; 21 } 22 23 public void setPassword(String password) { 24 this.password = password; 25 } 26 public String loginn() throws Exception { 27 System.out.println("login()"); 28 return "success"; 29 30 } 31 32 }
訪問連接
http://localhost:8080/Struts2Learn/loginAction_loginn.action