Spring項目的一些常見問題

  1. 404錯誤: 找不到頁面,檢查路徑是否正確
  2. form 表單傳輸的參數一定要全部寫進表單內。 如果不想顯示在頁面,使用hidden屬性。
<form id="updateForm" name="updateForm" class="form-inline"  method="post" style="margin-bottom: 10px;"> 

    <input type="hidden" class="form-control input-sm" id="id" name="id" maxlength="20" value="${student.id!''}"  style="margin-left:20px">

</form>


<script type="text/javaScript">


    function updateStudentInfo(){
        var updateForm = document.updateForm;
        updateForm.action = "${request.contextPath}/studentManage/updateStudentManage.action";
        updateForm.submit();
    }



</script>

3.如果使用頁面傳遞參數, 可以像第二條一樣用表單傳到後臺的controller裏, 也可以用ajax。需要注意的是, ajax只刷新當前頁面 ,彈出對話框。不能實現頁面的跳轉。

<table class="table   table-bordered table-condensed">
            <thead>
                <th>學生姓名</th>
                <th>年齡</th>
                <th>郵箱</th>
                <th>學號</th>
                <th>操作</th>

            </thead>
            <tbody>
       <#if (pageInfo??&&pageInfo?has_content)&&(pageInfo.list?has_content)> 
                <#list pageInfo.list as student>
                    <tr>
                        <td>${student.name!''}</td>
                        <td>${student.age!''}</td>
                        <td>${student.email!''}</td>
                        <td>${student.studentNo!''}</td>
                        <td class="btn btn-primary" style="float: middle;width:60px" onclick="deleteStudentInfo('${student.id!''}');"> 刪除 </td>
                        <td class="btn btn-primary" style="float: middle;width:60px" onclick="toNewOptUpd('${student.id!''}');"> 更新 </td>
                    </tr>
                </#list>
            <#else>
                <tr>
                    <td colspan="10" align="center">沒有查找到相應的數據!</td>
                </tr>
            </#if>
            </tbody>
        </table>

<form id="openFormIns" name="openFormIns" method="post"></form>

<script type="text/javaScript">
function deleteStudentInfo(id){
         $.ajax({
           type:"post",
           url:"${request.contextPath}/studentManage/delete.action",
           data:{'id':id},
           success:function(data){
           if (data == 'T')
         {
                selectStudentInfo();
        }
           else  {alert("刪除失敗!");}
           }
       });  
    }
function toNewOptUpd(id){  
       var openFormIns = document.openFormIns;
       openFormIns.action = "${request.contextPath}/studentManage/newOptUpd.action?id="+id;
       openFormIns.submit();
    }

</script>
  1. Jquery 表單操作不成功時,可以直接用JS語句。
function toNewOptUpd(id){  
       var openFormIns = document.openFormIns;
       openFormIns.action = "${request.contextPath}/studentManage/newOptUpd.action?id="+id;
       openFormIns.submit();
    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章