項目過程中遇到的問題集錦

1.ibatis中sql沒有問題,但是報出該問題: Cause: java.sql.SQLException: ORA-00911: 無效字符

原因:ibatis中的sql語句結尾不能添加";"

2.Invalid path was requested 無效路徑

原因:a,新添加的spring.xml以及struts.xml有沒有添加到web.xml中;

     b,strus.xml中的語法是否正確,可以檢查一下是否和別的struts格式是否一致(少了actionmappings);

     c,spring和struts中的action路徑name和path是否一致.

3.使用jquery.ajax實現下拉框無刷新顯示:

原因:如果返回的格式是json格式,一定要注意json的格式[{},{},{}],以及設置ajax返回的datatype爲json

$.get("<%=request.getContextPath()%>/customerInfo/customerInfoAction.do?method=getAllIndustry&type=2",{},

function (list){//回調函數

//清空下拉

$("#industry").empty();

$("#industry").append("<option value=''>請選擇</option>");

$.each(list  , function(i, item) {

$("#industry").append("<option value='"+item['industryId']+"'>"+item['industryName']+"</option>");

})

},'json');

//同等效果

$.ajax({

 type: "GET",

 url: "<%=request.getContextPath()%>/customerInfo/customerInfoAction.do?method=getAllIndustry&type=2",

 dataType: "json",

 success : function(data){

alert(data);

  $("#industry").empty();

  $("#industry").append("<option value=''>請選擇</option>");

  $.each( data  , function(i, item) {

$("#industry").append("<option value='"+item['industryId']+"'>"+item['industryName']+"</option>");

})

 }

}); 

在後臺的封裝爲:

String s = "[";

for (int i = 0; i < industryList.size(); i++) {

s += "{";

s += "'industryId':'" + industryList.get(i).getIndustry_Id() + "',";

s += "'industryName':'"+industryList.get(i).getIndustry_Name()+"'";

if(i == industryList.size()- 1) {

                   s += "}";

               } else {

                   s += "},";

               }

           }

s+="]";

response.getWriter().print(s);

response.getWriter().close();

發佈了30 篇原創文章 · 獲贊 2 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章