Java學習筆記(一)

在寫應用程序時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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章