神山树9196 2017-05-04 07:20 采纳率: 0%
浏览 689

json数据娶不到值。。大神指教

前台页面


                <li>
                <div class="fc">
                  <input name="id" type="hidden" id="id"/>                       
                </div>
              </li>
    
              <li>
                <label class="label">用户名:<span>*</span></label>
                 <div class="fc">
                  <input name="name" type="text" maxlength="40" id="name" value="${u.name}" />  <span class="tips">最多40个字符</span>
                 </div>
              </li>
    
              <li>
               <label class="label">邮箱:<span>*</span></label>
                <div class="fc">
                 <input name="email" type="text" maxlength="16" id="email" value="${u.email}" /> <span class="tips">最多16个字符</span>
                </div>
    
                            <script type="text/javascript">
    

    function Preservation(){
    alert("点击保存");
    var name = $("#name").val();
    alert("----用户信息---"+name);
    var email = $("#email").val();
    alert("---用户邮箱----"+email);
    var id = ${u.id}
    alert("---用户ID----"+id);
    $.ajax({
    url:"<%=request.getContextPath()%>/login_update.action",
    type:"post",
    data:{
    "id":id,
    "name":name,
    "email":email
    },
    dataType:"json",
    success:function(obj){
    if(obj){
    alert("修改成功!");
    location.href = "<%=request.getContextPath()%>/login_toMain.action;
    }
    else{
    alert("修改失败!");
    }

    }
    })

    }

    后台接收不到值,更新不了数据,/**
    * 修改action
    * @return
    * @throws IOException
    * @throws SQLException
    */
    public String update() throws SQLException {
    //通过ID找对象
    UserInfo userInfo = UserInfoDataProvider.getInstance().getUserInfoById(id);
    System.out.println("============"+userInfo.getName());
    System.out.println("----------------"+userInfo.getId());
    //更新
    UserInfoDataProvider.getInstance().updateUserInfo(userInfo);

        HttpServletResponse response = ServletActionContext.getResponse();
    
        JSONObject json = JSONObject.fromObject(userInfo);
    
        try {
            response.getWriter().write(json.toString());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
        return null;
    
    • 写回答

    1条回答 默认 最新

    • MathRandom 2017-05-04 07:28
      关注

      你用request取id看有不呢

      评论

    报告相同问题?

    悬赏问题

    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥15 stable diffusion
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘