当前位置: 代码迷 >> J2EE >> Action[/admin] does not contain method named 'login'解决思路
  详细解决方案

Action[/admin] does not contain method named 'login'解决思路

热度:305   发布时间:2016-04-22 02:11:45.0
Action[/admin] does not contain method named 'login'
报错说action里面找不到login方法,可action里面明明写了啊~~找半天找不到原因,求指导啊~
jsp:
<html:form action="/admin.do" method="post" onsubmit="return check()">
  <table width="258" height="150" border="0" cellspacing="0" cellpadding="2" align="center" bgcolor="c6fbff">
  <tr>
  <td align="right">用户名:</td>
  <td colspan="2"><html:text property="khid" style="width:144px" maxlength="30"/></td>
  </tr>
  <tr>
  <td align="right">密 码:</td>
  <td width="44%"><html:password property="pwd" style="width:144px" maxlength="20"/></td>  
  </tr>
   
  <tr align="center">
  <td colspan="3"><html:submit property="action" value="登录"/>  <input onClick=register() type="button" name="reg" value="注 册 "></td>
<html:hidden property="method" value="login"/>
  </tr>
   
  </table> 
</html:form>

struts-config:

<struts-config>
  <data-sources />
  <form-beans>
  <form-bean name="adminForm" type="com.hy.form.AdminForm"/>
  </form-beans>

  <global-exceptions />
  <global-forwards />
  <action-mappings>
  <action path="/admin"
  type="com.hy.action.AdminAction"
  attribute="adminForm"
  input="/login.jsp"
  parameter="method"
  name="adminForm"
  scope="request">
<set-property property="cancellable" value="true" />
<forward name="main" path="/WEB-INF/index.jsp"></forward>
<forward name="error" path="/WEB-INF/index.jsp"></forward>
   
  </action>
  </action-mappings>
  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>

action:

public class AdminAction extends DispatchAction{
Admin ad=null;
public static void main(HttpServletRequest request, HttpServletResponse response){
System.out.println("abc");
System.out.println(request.getParameter("method"));
}
 
public AdminAction()
{
ad=new Admin();
System.out.println("abc");
 
}
public ActionForward login(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response){
String s1=request.getParameter("adminid");
HttpSession session=request.getSession(true);
AdminForm adminForm=(AdminForm)form;
AdminDao ad=new AdminDaoImpl();
int a=ad.login(adminForm.getKhid(),adminForm.getPwd(),adminForm.getType());
if(a==1){
session.setAttribute("adminid", s1);
return mapping.findForward("main");
}
else
return mapping.findForward("error");

}

}

------解决方案--------------------
探讨
  相关解决方案