从序列化的form表单中取用户输入的数据

来源:互联网 发布:ipad无法加入网络 编辑:程序博客网 时间:2024/05/02 00:04

jsp代码:

 


拿select为例 :
<select name="studyingnature" >
 <c:forEach items="${allDetailsForm.studyingnatureList}" var="form" varStatus="s">
 <option value="${form.formid};${form.discription};${form.code}" <c:if test="${study.studyingnature==form.discription}">selected="selected"</c:if>>${form.discription}</option>
 </c:forEach>          
</select>

js代码:序列表单相当于url后加上 paraname=value&para2=value

function updateResumeAjax(){
  $.ajax({
  url: "#",  
  data : encodeURI($('#formid').serialize()),//formid 表单id
  dataType: "json",
  success: function(json){


    alert("更新用户信息完成!");
    location.href = "#";
    

  }   
     });
}

 

后台servlet:

String studyingnature = request.getParameter("studyingnature");//参数是 select的name属性
  try {
   studyingnature = URLDecoder.decode(studyingnature, "utf-8");
   if (StringHelper.isNullOrEmpty(studyingnature)) {
    String[] studyingnatures = studyingnature.split(";");
    study.setStudyingnature_code(studyingnatures[2]);
   }
  } catch (UnsupportedEncodingException e1) {
   // TODO Auto-generated catch block
   e1.printStackTrace();
  }

 

原创粉丝点击