ssh框架開發過程問題及其解決方法log

資料管理系統
開發環境:
- ssh框架:spring 3.2.4,struts 2.3,hibernate 3.6
- 數據庫:兼容達夢數據庫和oracle數據庫
- web服務器:tomcat
以下是項目開發過程中遇到的小問題彙總
1、 tomcat打開超時

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

解決:hibernate項目下默認只有slf4j日誌工具的api包,沒有實現包。登錄www.slf4j.org/download.html 下載slf4j日誌工具,解壓後將添加到lib目錄下。

Initializing Spring root WebApplicationContext
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

解決:項目中使用連接了數據庫的操作,而卻沒有開啓數據庫,直到tomcat連接數據庫超時之後纔會進行下一步,所以啓動比較慢。打開數據庫後再啓動tomcat。成功。
2、配置log4j文件時發現找不到文件問題
一般我們直接將log4j.properties放置在src目錄下,這樣系統自動會找到的,其實就是放在WEB-INF/classes文件下。這個路徑在classpath下,所以直接就能找到。如果現在我們想把log4j.properties文件放置在其它目錄下,例如:WEB-INF下和web.xml放在一起。這時候就需要我們手動指定log4j配置文件的路徑,否則系統是找不到的。
在web.xml中配置好log4j.properties路徑:

 <context-param>
     <param-name>log4jConfigLocation</param-name>
     <param-value>/WEB-INF/log4j.properties</param-value>
 </context-param>

3、hibernate映射文件問題
http-bio-8080-exec-4 : PERSON is not mapped from PERSON
配置文件

<hibernate-mapping>
  <class name="org.military.po.Warship" table="warship" schema="MilitaryMS" optimistic-lock="all" dynamic-update="true">
        <id name="shipversion" type="string">
            <column name="shipversion" length="100" />
            <generator class="assigned" />
        </id>
     ……
 </hibernate-mapping>

解決:因爲hql操作的是po,不是table,所以hql=“from Warship”,而不是寫成“from warship”。
4、無法解析的成員訪問表達式[PERSON0_.USERNAME]
達夢查詢語句會默認自動改成大些字母,如果在安裝數據庫時選擇大小寫敏感,而表名或者字段名爲小寫,則會報錯。
5、bootstrap或者html標籤寫的頁面跳轉到action時總是找不到?
解決:添加struts標籤引用<%@ taglib prefix =”s” uri =”/struts-tags”%>,在form元素前添加s:標記。form表單內的元素可以不添加s:前綴,只需輸入表單元素的name與action中封裝的屬性名稱一致即可。
本質原因:s:前綴會自動將action添加相應前綴路徑,另一個解決方法是更改action路徑:

String path = request.getContextPath();
action="<%=path%>/loginAction"

6、jsp文件中引入js文件時,js文件中的中文會亂碼
解決:eclipse中,在js文件上右擊,選擇屬性,選擇編碼方式爲utf-8(跟jsp編碼方式一致);
<script src ="./js/login.js" type ="text/javascript" charset ="utf-8">
7、ssh框架中,使用< a href=”“/>跳轉到/WEB-INF/文件夾下的jsp頁面方法
在struts.xml文件中配置

<action name= "*_*">
    <result> /WEB-INF/{1}/{2}.jsp </result>
</action>

然後在< a href=”<%=path>/admin_userInfo.jsp” />
其中String path = request.getContextPath();
表示將跳轉到/WEB-INF/admin目錄下的userInfo.jsp頁面
8、jsp中註銷功能實現
登錄action中登錄成功後添加session:

ActionContext.getContext().getSession().put("username", username);         
ActionContext. getContext().getSession().put( "password", userpassword );

在每個jsp顯示頁面頭部添加語句判斷:

String path=request.getContextPath();
Object username=session.getAttribute("username");
Object password=session.getAttribute("password");
if(username==null || password==null ){
       request.getRequestDispatcher( "/admin_login_first.jsp").forward(request, response);
}

當點擊註銷時,在註銷的jsp頁面中添加:

<%
session.removeAttribute("username");
session.removeAttribute("password");
%>

9、如果表單中有js處理代碼,而且提交後沒有跳轉到對應的action頁面,而是跳轉到了其他頁面,可以檢查下js文件中表單事件的submitHandler,去掉或修改即可。
10、action中配置的自定義方法只能是無參的,如果加上參數會找不到方法
如:

<action name= "registerCheckAction" class ="employeeAction" method="queryUserinfoBypage" >
      <param name= "state">未審覈 </param>
      <result name="success" >
      /WEB-INF/ admin/registerCheck.jsp</result >
 </action>

本想通過param傳遞參數給方法,但是報錯。所以不能這樣寫

11、js通過href傳參給action亂碼
方法:在href傳的參數 userlevel=encodeURI(encodeURI(level)) , 然後在action處理類中進行解碼:userlevel =URLDecoder.decode(userlevel, “utf-8”);
12、select列表框選擇問題
表格數據是動態生成的,當生成多行時,如果select組件id設爲固定的,那麼所有行的select組件id都一致,在用window.document.getElementById(id) 取數據時,實際上取的可能是第一行的數據。所以在生成表格select組件時,應根據表格主鍵設置不一樣的id,比如id =’level< s:property value =”username” /> ’ ,而在取值時,可以

var obj1=window.document.getElementById('level <s:property value= "username" /> ');                                                                                               
 var level=obj1.value; 

小技巧:因爲取得select選中的文本比較麻煩,可以將value設置成和文本值一致,這樣使用 var level=obj1.value 取value值即可。
13、state狀態改成varchar(20),如果是char(20)屬性,不滿足20個長度的會補空格,那在判斷跟某一字符相等時可能會出現錯誤。
14、使用jquery.validate.js驗證表單時出現TypeError: $(…).validate is not a function錯誤
原因:檢查jquery.min.js文件是否導入不同版本
jquery.validate.min.js文件是否導入。兩者引用順序不可改變
15、TypeError: $(…).pagination is not a function
遇到該類……不是一個函數之類的問題,往往是由於js包衝突,該問題就是由於引入的兩個jquery版本衝突造成的。
注意:同一個jquery.js引入兩次也會出錯。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章