日期:2014-05-19  浏览次数:20746 次

请问logon是不是struts2的保留字段,奇怪问题
我用struts2做了一个登录的小例子,很简单的,一个输入页面(index.jsp),一个action(类名:LogonAction),还有两个页面,一个成功,一个失败页面,这两个页面都很简单。情况是这样的,当我把struts.xml里的action名字改为logon时总是报
No result defined for action com.yan.web.action.LogonAction and result success,当我把随便改一下logon名字时比如改为logon1就可以正常运行,在网上找struts2的保留字段也找到什么,奇怪,请教各位。我把我用到的代码贴在下边:

struts.xml
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<!-- START SNIPPET: xworkSample -->
<struts>

  <package name="default" extends="struts-default">
  <action name="logon" class="com.yan.web.action.LogonAction">
  <result name="success">/success.jsp</result>
  <result name="error">/failure.jsp</result>
  </action>
  </package>
   
</struts>

<!-- END SNIPPET: xworkSample -->

index.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<% String base = request.getContextPath(); %>

</head>

<body>
<form action="logon.action" method="post">
  <div style="color:red"><s:fielderror /></div>
  <!-- 读取显示提示信息 -->
  <table>
  <tr>
  <td>
  用户名:
  </td>
  <td>
  <input type="text" name="user.userName"/>
  </td>
  </tr>
  <tr>
  <td>
  密码:
  </td>
  <td>
  <input type="password" name="user.password"/>
  </td>
  </tr>
  <tr>
  <td>
  年龄:
  </td>
  <td>
  <input type="text" name="user.userLevel"/>
  </td>
  </tr>
  <tr>
  <td>
  生日:
  </td>
  <td>
  <input type="text" name="user.agentNumber"/>
  </td>
  </tr>
  <tr>
  <td colspan="2">
  <s:submit value="注册"></s:submit>
  </td>
  </tr>
  </table>
  </form>

</body>
</html>

LogonAction.java

package com.yan.web.action;

import com.opensymphony.xwork2.ActionSupport;
import com.yan.entity.User;

public class LogonAction extends ActionSupport {
  private static final long serialVersionUID = 4991026832999229787L;
  private User user;
   
  @Override
  public String execute() {
   
  return