struts2的一个例子,找不到action。。。。。。

这是我的配置文件:

<struts>
 <constant name="struts.enable.DynamicMethodInvocation" value="true" />
 <constant name="struts.devMode" value="true" />
 
 <package name="default" namespace="/" extends="struts-default">
  <action name="login" class="com.net.ActionTest" method="execute">
   <result name="success">/welcome.jsp</result>
  </action>
 </package>

</struts>

 

这是我的jsp表单:

<s:form action="login.action" >
  <s:label value="系统登陆"></s:label>
  <s:textfield name="username" />
  <s:password name="password" />
  <s:submit value="登录" />
 </s:form>

 

这是我的action:

public class ActionTest extends ActionSupport {

@Override
 public String execute() throws Exception {
   return "success";
 }
}

 

访问http://127.0.0.1:8080/mint/login.jsp后结果:

警告: No configuration found for the specified action: 'login.action' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
2012-9-8 22:56:17 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find action or result
There is no Action mapped for namespace / and action name login. - [unknown location]

 

2种方式:
1.直接用

html标签
2.在使用struts2 from标签的时候 action不需要.action

这个.action不能由我们手工添加,Struts2会自动为你完成这个工作,并且手工添加是不行的,就不必多此一举了.但是在其他的场合,比如使用html标签超级链结,则可以加上这个.action。

刚刚把你的代码贴过来试了一下,没有报错啊!只是在加载时出现了警告。