錯誤形式
當點擊 “添加題目”按鈕的時候,正常是彈出添加按鈕的對話框。可是卻出現了下面的404錯誤:
源碼分析
運行流程
部分源代碼:
single.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- 引入commons.jsp -->
<%
String path = request.getContextPath()+"/" ;
%>
<base href="<%=path %>" />
<%@ include file="/commons.jsp" %>
<script src="js/questions/single/single.js"></script>
<div id="singleGrid"></div>
<div id="singleDialog"></div>
single.js(主要)
$(function(){
singleFn.loagGrid();
})
var singleFn = {
loagGrid:function(){
$("#singleGrid").datagrid({
title:"單選題列表",
rownumbers:true,//在表格的前頭,顯示行列號
striped:true,//是否顯示斑馬線效果
fit:true,//自適應整個頁面
fitColumns:true,//列的自適應
pagination:true,//是否分頁
url:'questions/single/singles.do',//當前頁面加載前,發送的請求
//列屬性
columns:[[
{field:'sno',title:'單選題編號',hidden:true},
{field:'stext',title:'試題文本',width:100,align:'center'},
{field:'soptions',title:'選項',width:100,align:'center'},
]],
toolbar:[{
id:'btn1',
text:'添加題目',
iconCls:'icon-add',
onClick:function(){
//
singleFn.toAdd();
}
}],
})
},
toAdd:function(){
$('#singleDialog').dialog({
title:'添加單選',
width:330,
height:235,
href:'/jsps/questions/single/singleForm.jsp',//錯誤主要在這裏
modal:true,
onLoad:function(){
//其他操作
}
})
},
}
singleForm.jsp(部分)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<div style="margin-top:10px; margin-left:10px">
<form id='singleForm' method="post">
<div style="width:100%;margin-top:3px;">
<font size="2">請選擇試題難度:</font>
<select id="stype" name="stype" style="width:100%;max-width:150px;">
<option selected="selected" value="1">簡單</option>
<option value="2">一般</option>
<option value="3">困難</option>
</select>
</div>
</form>
</div>
產生原因
觀察可知道:我們錯誤的原因是因爲找不到singleForm.jsp這個文件,但是路徑明明沒有錯誤。
所以,錯誤肯定就是在 href:'/jsps/questions/single/singleForm.jsp',
所以,我試着修改路徑爲jsps/questions/single/singleForm.jsp'
就是隻把jsp前面的斜線去掉了。就可以了
解決辦法
將路徑 “/jsps/questions/single/singleForm.jsp'”
修改爲 “jsps/questions/single/singleForm.jsp'”
成功: