Java学习笔记(一)

本文围绕Struts应用程序展开,执行功能时抛出'No input attribute for mapping path'错误。分析了ExamOwnBatchAddForm.java中validate和reset方法缺少参数、ExamOwnBatchAddAction.java缺少返回语句的问题,还探讨了perform和execute方法的区别及perform方法使用时的弃用提示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在写应用程序时Struts时 当在执行该功能时,抛出以下错误;

HTTP Status 500 - No input attribute for mapping path /examOwnBatchAddAction
--------------------------------------------------------------------------------
type Status report

message No input attribute for mapping path /examOwnBatchAddAction

description The server encountered an internal error (No input attribute for mapping path /examOwnBatchAddAction) that prevented it from fulfilling this request.

//ExamOwnBatchAddForm.java
import org.apache.struts.action.*;
import javax.servlet.http.*;

public class ExamOwnBatchAddForm extends ActionForm {

  private String qcode;
  private String ucode;
  private String action;
  
  public String getQcode() {
    return qcode;
  }
  public void setQcode(String qcode) {
    this.qcode = qcode;
  }
   public String getUcode() {
    return ucode;
  }
  public void setUcode(String ucode) {
    this.ucode = ucode;
  }
  public String getAction() {
    return action;
  }
  public void setAction (String action) {
    this.action = action;
  }
  public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) {
   
/**@todo: finish this method, this is just the skeleton.*/
    ActionErrors errors = new ActionErrors();
    if (ucode==null||ucode.equals("")){
      errors.add(ucode, new ActionError("error.exam.nullucode"));
    }
    return errors;
  }
  public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) {
  }
}

//ExamOwnBatchAddAction.java
public class ExamOwnBatchAddAction extends Action {
   public ActionForward perform(ActionMapping actionMapping,
                                ActionForm actionForm,
                                HttpServletRequest httpServletRequest,
                                HttpServletResponse httpServletResponse){
    //execute  perform
     ExamOwnBatchAddForm examOwnBatchAddForm = (ExamOwnBatchAddForm) actionForm;
     String action = httpServletRequest.getParameter("action");
    
     HttpSession session = httpServletRequest.getSession();
     String ucode = (String) session.getAttribute("ucode");
     String qcode = (String) session.getAttribute("qcode");
     String target = ""; 
     if ((ucode==null)||(ucode.equals("")))
     {
       target = "login";
     }
     else if (action.equals("BatchAdd"))
     {
      Exam exam = new Exam();
      exam.setBatchAddExamDetail(ucode,qcode);
       target = "success"; 
     }
    return actionMapping.findForward(target);
   }
}

//Struts-conifg.xml
<struts-config>
  <form-beans>
    <form-bean name="examOwnBatchAddForm" type="ExamOwnBatchAddForm" /> 
  </form-beans>
 <global-forwards>
    <forward name="errors" path="/insertError.jsp" />
    <forward name="login" path="/index.jsp" />
  </global-forwards>
  <action-mappings>
    <action name="examOwnBatchAddForm" type="ExamOwnBatchAddAction" validate="true" scope="request" path="/examOwnBatchAddAction">
      <forward name="success" path="/examListAction.do" />
    </action>

问题1:当在ExamOwnBatchAddForm.java中的public ActionErrors validate( )和public void reset( )中缺少“HttpServletResponse httpServletResponse”时即会抛出开头错误;当在validate( )中写入后则程序执行正常。

问题2:在ExamOwnBatchAddAction.java 中如果不写入return actionMapping.findForward(target); 则编译时提示missing return statement

问题3:在public ActionForward perform( ) 和 public ActionForward execute( ) 两者的区别?使用perform编译后会提示
Note: ExamOwnBatchAddAction.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值