4
回答
MyEclipse里Strust1为什么form的验证都执行了,可是跳不到action中
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

action的配置文件没有错请放心,我和朋友看了很多遍

actionform

public class UsersTicketForTrainIDForm extends ActionForm {
 private String date_train;
 private String start_station;
 private String end_station;
 
 public String getDate_train() {
  return date_train;
 }
 public void setDate_train(String dateTrain) {
  date_train = dateTrain;
 }
 public String getStart_station() {
  return start_station;
 }
 public void setStart_station(String startStation) {
  start_station = startStation;
 }
 public String getEnd_station() {
  return end_station;
 }
 public void setEnd_station(String endStation) {
  end_station = endStation;
 }
 
 public UsersTicketForTrainIDForm(String dateTrain, String startStation,
   String endStation) {
  super();
  date_train = dateTrain;
  start_station = startStation;
  end_station = endStation;
 }
 
 
 public UsersTicketForTrainIDForm() {
  super();
 }
 @Override
 public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {
  
  ActionErrors actionErrors = new ActionErrors();
  if(date_train==null||date_train.trim().length()<=0)
  {
   ActionMessage actionError = new ActionMessage("error.date_train.null");
   actionErrors.add("date_train.null",actionError);
  }
  if(start_station==null||start_station.trim().length()<=0)
  {
   ActionMessage actionError = new ActionMessage("error.start_station.null");
   actionErrors.add("start_station.null",actionError);
  }
  if(end_station==null||end_station.trim().length()<=0)
  {
   ActionMessage actionError = new ActionMessage("error.end_station.null");
   actionErrors.add("end_station.null",actionError);
  }
  return actionErrors;

}
}

action

<form action="TrainListForTrainID.do" method="post" id="UsersTicketForTrainIDForm" onsubmit="return test_form(this)">
      <input type="text" size="25"  name="start_station"/><br>
       <input type="text" size="25"  name="end_station"/> <br>
       <input type="submit"  value="sub"/>
     </form>
     <table border="1">
     <% request.getSession().getAttribute("TrainBeanListForTrainID") ;%>
     <tr>
      <td>
       ${TrainBeanListForTrainID.train_id}
      </td>
      <td>
       ${TrainBeanListForTrainID.start_station}
      </td>
      <td>
       ${TrainBeanListForTrainID.end_station}
      </td>
      <td>
       ${TrainBeanListForTrainID.start_time}
      </td>
      <td>
       ${TrainBeanListForTrainID.end_time}
      </td>
      <td>
       ${TrainBeanListForTrainID.all_time}
      </td>
      <td>
       ${TrainBeanListForTrainID.all_distance}
      </td>
      <td>
       ${TrainBeanListForTrainID.ticket_price}
      </td>
      <td>
       ${TrainBeanListForTrainID.type_ticket}
      </td>
      <td>
       ${TrainBeanListForTrainID.type_train}
      </td>
      
     </tr> 

action

 

public class TrainListForTrainIDAction extends Action {

 @Override
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  
  request.setCharacterEncoding("UTF-8");
  UsersTicketForTrainIDForm UsersTicketForTrainIDForm=(UsersTicketForTrainIDForm)form;
  
  String start_station=UsersTicketForTrainIDForm.getStart_station();
  String end_station=UsersTicketForTrainIDForm.getEnd_station();
  try {
   start_station = URLDecoder.decode(start_station,"UTF-8");
   end_station = URLDecoder.decode(end_station,"UTF-8");
  } catch (Exception e) {
   
   e.printStackTrace();
  }
  ArrayList<TrainBean> TrainBeanListForTrainID =TrainDAO.FindTrainByTrain_Station(start_station,end_station);
  if(TrainBeanListForTrainID!=null)
  {
  request.getSession().setAttribute("TrainBeanListForTrainID", TrainBeanListForTrainID);
  return mapping.findForward("TrainListForTrainIDSuccess");
  }
  else
  {
   request.setAttribute("TrainListForTrainIDWrong", "TrainListForTrainIDwrong");
   return mapping.getInputForward();}
 }
 

}

 希望高手指点一下,配置文件里没有错,源程序的sql没有写进来,因为action都没有执行,源文件我还有个乱码过滤器,不知道是否有影响

举报
顶部