JAVAWEB項目編寫遇到的問題及解決方法
請求轉發到主頁面錯誤的在iframe打開解決方法
由於篇幅有限在這裏只貼出有關問題的代碼
下面是usermain.jsp,點擊會轉發到上傳頭像經過後臺請求轉發到另一個photo.jsp頁面
usermian.jsp
<li>
<a href="${pageContext.request.contextPath }/fileupservlet
?method=fileuppage" id="fileupphoto" target="usernameframe">
上傳頭像</a>
</li>
photo.jsp包含一個模態框,模態框外面有一個form表單,經過form表單提交會上傳到服務器同時在數據庫進行更新,最後轉發回usermain.jsp頁面,問題在於經過請求轉發到usermain.jsp頁面的時候,會在之前usermain.jsp中上傳頭像的target目標中打開,即usermian.jsp在iframe中打開,很顯然不是我們想要的效果,在這裏我們請求轉發到一箇中間的頁面usermianjump.jsp,然後再打開usermian.jsp
photo.jsp
<!-- Modal -->
<form action="${pageContext.request.contextPath }/fileupservlet?method=headportrait&confim=confim" method="post" enctype="multipart/form-data">
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">選擇頭像</h4>
</div>
<div class="modal-body">
<input class="upload-file-img" type="file" name="personsFile" id="personsFile" multiple="multiple" accept="image/*" οnchange="uploadImg()" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="submit" class="btn btn-success" name="confim" value="confim">確定上傳</button>
</div>
</div>
</div>
</div>
</form>
這裏使用usermianjump.中使用parent.location.href在父頁面打開新頁面,進行usermain.jsp的跳轉,最後取得想要達到的效果
usermianjump.jsp
<script type="text/javascript">
$(function(){
parent.location.href="${pageContext.request.contextPath}
/jump?method=usermainjump";
});
</script>
javascript中的location.href的多種用法
目前在開發中經常要用到的幾種形式有:
self.location.href;//當前頁面打開URL頁面
window.location.href;//當前頁面打開URL頁面
this.location.href;//當前頁面打開URL頁面
location.href;// 當前頁面打開URL頁面
parent.location.href;//在父頁面打開新頁面
top.location.href;//在頂層頁面打開新頁面
經常見到的大概有以上幾種形式。
注:
①如果頁面中自定義了frame,那麼可將parent、self、top換爲自定義frame的名稱
, 效果是在frame窗口打開url地址。
②此外,window.location.href=window.location.href;和window.locati
on.Reload();都是刷新當前頁面。區別在於是否有提交數據。當有提交數據時windo
w.location.Reload()會提示是否提交window.location.href=window.locat
ion.href;則是向指定的url提交數據.
③用window.open()打開新頁面 但是用window.location.href="" 卻是在原窗口
打開的. 有時瀏覽器會一些安全設置window.open肯定被屏蔽。例如避免彈出廣告窗口。
DBUtils中QueryRunner返回結果集對象總結
QreryRunner類(org.apache.commons.dbutils.QueryRunner)
1. query(Connection conn, String sql, Object[] params,
2. ResultSetHandler rsh)
執行選擇查詢,在查詢中,對象陣列的值被用來作爲查詢的置換參數。
2.query(String sql, Object[] params, ResultSetHandler rsh)
方法本身不提供數據庫連接,執行選擇查詢,在查詢中,對象陣列的值被用來作爲查詢
的置換參數。
3.query(Connection conn, String sql, ResultSetHandler rsh)
執行無需參數的選擇查詢。
4.update(Connection conn, String sql, Object[] params)
被用來執行插入、更新或刪除(DML)操作。
其中ResultSetHandler接口(org.apache.commons.dbutils.ResultSethandler)執行處理一個結果集對象,將數據轉變並處理爲任何一種形式,供其他應用使用。實現類如下:
ArrayHandler:把結果集中的第一行數據轉成對象數組。
ArrayListHandler:把結果集中的每一行數據都轉成一個對象數組,再存放到List中。
BeanHandler:將結果集中的第一行數據封裝到一個對應的JavaBean實例中。
BeanListHandler:將結果集中的每一行數據都封裝到一個對應的JavaBean實例中,存放到List裏
MapHandler:將結果集中的第一行數據封裝到一個Map裏,key是列名,value就是對應的值。
MapListHandler:將結果集中的每一行數據都封裝到一個Map裏,然後再存放到List
ColumnListHandler:將結果集中某一列的數據存放到List中。
KeyedHandler(name):將結果集中的每一行數據都封裝到一個Map裏(List<Map>),再把這些map再存到一個map裏,其key爲指定的列。
ScalarHandler:將結果集第一行的某一列放到某個對象中。