HTTP ERROR400的問題解決


今天寫添加功能,在點添加提交時報了一個“HTTP ERROR 400”的錯誤,如圖,

請求提交的代碼死活跳轉不到后台,郁悶中,開啟debug功能,開始一步步排查,

1、先單獨把跳轉鏈接“http://192.168.1.72:8080/securityMonitor_C/device/insert”,放到瀏覽器中測試,發現可以跳轉到后台的insert方法,那么不是跳轉方法寫錯的問題,那是什么原因呢,打開foxfixe瀏覽器在的開發者工具,如圖:

 

 找到了報錯的那條請求,原以為是請求中沒有域名的問題,看到請求中域名與參數都是有的,那么會是什么錯呢?與同事討論,說會不會是帶的參數有問題,好吧

這也是一條思路,把這條請求取出來:

http://192.168.1.72:8080/securityMonitor_C/device/insert?equipmentNo=t001&equipmentType=1&videoUrlLow=d&videoUrlCentre=&videoUrlHigh=&videotapeUrl=&cloudControlUrl=&areaId=&regionId=&status=1&controltId=&namagerUrl=&instalLatitude=d&equipmentModel=&installTime=

先把完整的放在瀏覽器中測試,瀏覽器中,果斷報錯,好吧,算是找到了一點小進步,那么下一步,開始減少傳遞的參數一步一步的試吧,首先把最后一個參數(&installTime=)去掉,再把鏈接拿到瀏覽器中測試,發現沒有報錯,可以進入后台(慶祝一下),到這一步,可算是找到問題原因了,是因為installTime這個參數的原因

可是問題又來了,為什么它會導致鏈接跳轉不到后台呢?

然后我又回到jsp頁面,仔細分析jsp頁面代碼:

<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ include file="/WEB-INF/views/taglibs.jsp" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
.urlinput{border:1px solid #95b8e7;border-radius:5px;width:200px;padding:2px;}
</style>
</head>
<body>
<form id="form1" action="insert">
<div class="dialogPage">
<div class="om-panel-header">新增</div>
<div class="editDiv">
<table class="editTable">
<tr>
<td><span class="required">*</span>設備編碼:</td>
<td><input type="text" id="equipmentNo" name="equipmentNo"></td>
<td><span class="required">*</span>設備類型:</td>
<td><input type="combo" id="equipmentType" name="equipmentType" ></td>
</tr>
<tr>
<td><span class="required">*</span>實時低視頻播放URL:</td>
<td colspan="3"><input type="text" id="videoUrlLow" name="videoUrlLow"></td>
</tr>
<tr>
<td>實時中視頻播放URL:</td>
<td colspan="3"><input type="text" id="videoUrlCentre" name="videoUrlCentre"></td>
</tr>
<tr>
<td>實時高視頻播放URL:</td>
<td colspan="3"><input type="text" id="videoUrlHigh" name="videoUrlHigh"></td>
</tr>
<tr>
<td>錄像播放URL:</td>
<td colspan="3"><input type="text" id="videotapeUrl" name="videotapeUrl" ></td>
</tr>
<tr>
<td>雲台控制URL:</td>
<td colspan="3"><input type="text" id="cloudControlUrl" name="cloudControlUrl"></td>
</tr>
<tr>
<td>地區:</td>
<td><input type="text" id="areaId" name="areaId"></td>
<td>區域屬性:</td>
<td><input type="combo" id="regionId" name="regionId"></td>
</tr>
<tr>
<td><span class="required">*</span>狀態:</td>
<td><input type="combo" id="status" name="status"></td>
<td>受控屬性:</td>
<td><input type="combo" id="controltId" name="controltId"></td>
</tr>
<tr>
<td>管理url:</td>
<td colspan="3"><input type="text" id="namagerUrl" name="namagerUrl"></td>
</tr>
<tr>
<td><span class="required">*</span>安裝位置:</td>
<td><input type="text" id="instalLatitude" name="instalLatitude"></td>
<td>設備規格型號:</td>
<td><input type="text" id="equipmentModel" name="equipmentModel"></td>
</tr>
<tr>
<td>安裝時間:</td>
<td><input type="datetime" id="installTime" name="installTime" class="easyui-datetimebox"></td>
</tr>
</table>
<div class="editBtn">
<button type="submit" class="button">&nbsp;保存&nbsp;</button>
<button type="button" class="button" onclick="javascript:art.dialog.close();">&nbsp;關閉&nbsp;</button>
</div>
</div>
</div>
</form>
</body>
<script type="text/javascript">
$(function(){
//調整樣式
$("#mobile").css("width","435px");
$("#videoUrlHigh").css("width","435px");
$("#videoUrlCentre").css("width","435px");
$("#videoUrlLow").css("width","435px");
$("#videotapeUrl").css("width","435px");
$("#cloudControlUrl").css("width","435px");
$("#namagerUrl").css("width","435px");

//添加校驗
$('#equipmentNo').validatebox({
required:true,
validType:'maxLength[32]'
});
$('#equipmentType').validatebox({required:true});
$('#videoUrlLow').validatebox({required:true,validType:'maxLength[64]'});
$('#videoUrlCentre').validatebox({validType:'maxLength[64]'});
$('#videoUrlHigh').validatebox({validType:'maxLength[64]'});

$("#videotapeUrl").validatebox({validType:'maxLength[64]'});
$("#cloudControlUrl").validatebox({validType:'maxLength[64]'});
$("#namagerUrl").validatebox({validType:'maxLength[64]'});
$('#instalLatitude').validatebox({required:true});

//初始下拉列表
$('#equipmentType').combobox({
data:JSON.parse('${deviceTypeCombo}'),
panelHeight:'auto',
editable:false,
value:1
});

$('#regionId').combobox({
data:JSON.parse('${regionCombo}'),
panelHeight:'auto',
editable:false,
// value:1
});

$('#controltId').combobox({
data:JSON.parse('${controltCombo}'),
panelHeight:'auto',
editable:false,
// value:1
});

$('#status').combobox({
data:JSON.parse('${statusCombo}'),
panelHeight:'auto',
editable:false,
value:1
});
$(":submit").click(function(){
if(!$("#form1").form('validate')){return false;}
});
});
</script>
</html>

發現installTime是date類型,但這應該不會是引起跳轉不到后台的問題吧,(這里要說明一下,我前端框架使用的是easyUI),於是我想是不是后台接收請求,將請求轉換成對應的bean時出現問題了呢,后台的接收方法:

@RequestMapping(value = "insert")
public String insert(HttpServletRequest request, Equipment equipment) {
equipment.setCreateOpId(super.getUserObj(request).getUserId()
.shortValue());
equipment.setCreateTime(new Date());
equipmentService.persist(equipment);
return "success";
}

於是,開始一步步做測試,1、先把方法中將請求映射成 equipment對象給去掉,即不讓它自動轉化為Equipment對象。重啟請求,添加數據,提交,OK斷點可以進來。這里已經找到問題出現點了。那么開始分析 為什么加上自動轉化為Equipment對象會報錯呢

會不會Equipment對象的installTime成員變量的類型設置的問題引起的呢,於是打開Equipment對象,發現installTime成員變量的類型設置的是Date類型,目前因為這個類型會導致報錯,於是將其改為String類型,然后再重啟,測試,ok,測試通過。

錯誤總結:

bean對象的參數如果是date類型的,那么date類型從頁面上轉化為bean對象時就會有問題。最好是將存儲時間的變量設置為String,這樣就可以避免一些問題。當然我得出的結果的前提是在使用easyUI的框架下,其它的jquery框架有沒有這個問題,需要待驗證


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM