㈠ spring 怎麼管理ibatis的session,spring事務管理後 會關閉session么在源碼中怎麼查看
首先要明白spring為什麼要管理session?session是在什麼時候使用的?以及為什麼要管理?
1、spring其實管理的是sessionFactory對象,很明顯這個對象是用來獲取session的。在spring上下文全局中應該只有一個,這個不用擔心因為默認情況下spring都是管理bean都是單例的。
2、session是線程不安全的,因此我們使用的是時候應當使用局部變數的方式使用。也就是方法體內使用
3、先看圖
可能你覺得這個比較發麻,這么簡單的一個方法我手動控制就好了!但是實際應用當中可能你這個業務方法還調用其他的業務方法,那時候你這個事務要怎麼控制,是全部寫在一個try-catch裡面還是怎麼處理?
㈡ java中session是不是一個類,如是,源代碼是什麼
叫某個人講 真的不好講
在java裡面用的東西都是類 因為java是純面向對象的語言
下面給你一些方法
Method Summary
Object getAttribute(String name)
Returns the object bound with the specified name in this session, or null if no object is bound under the name. 返回session中指定名稱的綁定對象,如果沒有對象被綁定,返回null。
Enumeration getAttributeNames()
Returns an Enumeration of String objects containing the names of all the objects bound to this session. 以String對象的枚舉形式返回綁定給該session的所有對象名稱。
long getCreationTime()
Returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.返回session創建的時間,以1970年1月1日0點為起點。
String getId()
Returns a string containing the unique identifier assigned to this session. 返回一字元串,表示分配給session的唯一的標識符。
long getLastAccessedTime()
Returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT, and marked by the time the container received the request. 返回上一次該會話相關的客戶端請求時間,表示為從GMT 1970年1月1日以來的毫秒值,標記為容器接收到請求的時間。
int getMaxInactiveInterval()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. 以秒為單位返回最大間隔時間,在客戶端訪問之間servlet容器將保持會話開啟。
ServletContext getServletContext()
Returns the ServletContext to which this session belongs. 返回session屬於的ServletContext。
HttpSessionContext getSessionContext()
Deprecated. As of Version 2.1, this method is deprecated and has no replacement. It will be removed in a future version of the Java Servlet API. 從版本2.1以來,該方法不再支持,且沒有替代方法。在Java Servlet API的以後版本中將被刪除。
Object getValue(String name)
Deprecated. As of Version 2.2, this method is replaced by getAttribute(java.lang.String). 從版本2.2以來,該方法被getAttribute(java.lang.String)所替代。
String[] getValueNames()
Deprecated. As of Version 2.2, this method is replaced by getAttributeNames() 從版本2.2以來,該方法被getAttributeNames()所替代。
void invalidate()
Invalidates this session then unbinds any objects bound to it. 使session無效,解除所有對象的綁定。
boolean isNew()
Returns true if the client does not yet know about the session or if the client chooses not to join the session. 如果客戶端不知道該會話或者沒有選擇加入該會話,返回true。
void putValue(String name, Object value)
Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object) 從版本2.2以來,該方法被setAttribute(java.lang.String, java.lang.Object)所替代。
void removeAttribute(String name)
Removes the object bound with the specified name from this session. 從session中刪除指定名稱綁定的對象。
void removeValue(String name)
Deprecated. As of Version 2.2, this method is replaced by removeAttribute(java.lang.String) 從版本2.2以來,該方法被removeAttribute(java.lang.String)所替代。
void setAttribute(String name, Object value)
Binds an object to this session, using the name specified. 使用指定名稱,向session綁定一個對象。
void setMaxInactiveInterval(int interval)
Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. 以秒為單位指定servlet容器使會話失效之前客戶端請求之間的間隔時間。
我建議你去找一個java幫助文檔自己分析
㈢ Hibernate--Session的createQuery源代碼
org.hibernate.impl.SessionImpl.java
public Query createQuery(String queryString) {
errorIfClosed();
checkTransactionSynchStatus();
return super.createQuery(queryString);
}
㈣ java springboot +beetl 項目怎麼實現國際化
國際化(internationalization)是設計和製造容易適應不同區域要求的產品的一種方式。它要求從產品中抽離所有地域語言,國家/地區和文化相關的元素。換言之,應用程序的功能和代碼設計考慮在不同地區運行的需要,其代碼簡化了不同本地版本的生產。開發這樣的程序的過程,就稱為國際化。
那麼當我們使用Spring Boot如何進行國際化呢?那麼當你讀完這篇文章你會學到如下知識:
(1) spring boot 加入thymeleaf;
(2) 頁面元素國際化;
(3) spring boot默認國際化原理說明;
(4) firefox瀏覽器修改區域語言;
(5)chrome瀏覽器修改區域語言;
(6)修改默認messages配置前綴;
(7) 代碼中如何獲取國際化信息;
(8) 優化代碼獲取國際化信息;
(9) 區域解析器之AcceptHeaderLocaleResolver;
(10) 會話區域解析器之SessionLocaleResolver;
(11) Cookie區域解析器之CookieLocaleResolver;
(12)固定的區域解析器之FixedLocaleResolver ;
(13)使用參數修改用戶的區域;
㈤ 如何實現 Spring MVC i18n 國際化,動態設置默認語言
1.在spring配置文件中配置資源文件properties的位置及公共名,下列配置指定的properties文件處於src目錄下的resources文件夾中,名字為message_info_*.properties。
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<propertyname="basenames">
<list>
<value>resources/message_info</value>
</list>
</property>
<propertyname="useCodeAsDefaultMessage"value="true"/><!--
Set whether to usethe message code as default message instead of
throwing aNoSuchMessageException. Useful for development
anddebugging. -->
</bean>
2.在spring配置文件中配置基於session的處理,將提交上來的locale參數進行處理,下列代碼默認載入的語言是中文簡體。
<bean id="localeResolver"class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<propertyname="defaultLocale"value="zh_CN"></property>
</bean>
3.在spring配置文件中的controller內配置相應的攔截器。
<beanid="className"
class="org.springframework.web.servlet.mvc.support.">
<propertyname="interceptors">
<list>
<beanclass="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
</list>
</property>
</bean>
4.相應的properties文件內寫入對應的語言,配置文件的語言信息以keyvalue的形式進行存儲。
5.利用jstl的fmt標簽庫進行相應數據的國際化。
1)導入相應的fmt標簽庫<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
2)需要國際化處寫入<fmt:messagekey="title"></fmt:message>標簽,此處將顯示相應properties文件中名為title的信息。
3)頁面上寫成三個連接用於控制國際化的轉換
<ahref="/CloudPortal/staff/goindex.do?locale=zh_CN">Chinese</a>//message_info_zh_CN.properties
<ahref="/CloudPortal/staff/goindex.do?locale=en_US">English</a>//message_info_en_US.properties
<ahref="/CloudPortal/staff/goindex.do?locale=zh_TW">Chinese(TW)</a>//message_info_zh_TW.properties
locale內部固定的參數用於判斷讀取請求的配置文件。
-------------------------------------------------------------
分割線--------------2014-11-11 by
zhang------------------------------------------------------------------------------------------------------
springmvc如何實現國際化
1.springmvc實現國際化有多種方式(自行網路)。
幾種方式無非就是配置國際化方式和讀取國際化資源文件從而實現國際化,下面本文介紹基於session的國際化配置,感覺配置比較方便快捷一些。
(1).首先配置配置國際化在spring-servlet.xml,即springmvc的配置文件中(xxx-servlet.xml)。
<!-- springmvc 國際化配置 (基於Session的國際化配置 方式)-->
<bean id="localeResolver"
class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
</bean>
<bean id="messageSource"
class="org.springframework.context.support.">
<property name="fallbackToSystemLocale">
<value>false</value>
</property>
<property name="basename" value="/WEB-INF/i18n/resources/messages" />
</bean>
(2)在WEB-INF文件夾下按照
[html] view plain
/WEB-INF/i18n/resources/messages
配置新建文件夾,在文件夾裡面新建配置文件
messages_zh_CN.properties(中文國際化資源文件),messages.properties(英文國際化資源文件)國際化資源文件。
到此配置完畢。
註:springmvc的國際化必須要經過控制器Controller才能生效。
2.如何在jsp頁面讀取國際化
(1)引入<spring:message/>標簽如:<spring:message key=''user.manage.role/>
或者
(2)引入<fmt:message/>標簽例如<fmt:message key='user.manage.role'/>,其中user.manage,role在messages_zh_CN.properties中配置為:user.manage.role=\u89D2\u8272,在messages.properties中配置為user.manage.role=Role,即可。
㈥ javaee相關的問題有關Session、ResultSet的底層實現
httpsession的取得和設值可google
resultset是資料庫查詢結果,沒有get和set方法。
你多看看java基礎才好入門
㈦ 基於Session的國際化配置,解決後加高分
這個是我成功配置的經驗
1.安裝apache_2.2.4-win32-x86-no_ssl.msi到 d:\phpWeb\APACHE\
步驟:下一步下一步
2.安裝php-5.2.0-Win32.zip 到 d:\phpWeb\php\
步驟:(1)解壓壓縮包到d:\phpWeb\php\
(2)找到php目錄里的 php.ini-dist 重命名為 php.ini 並拷到 windows目錄里
(3)將php目錄里的 php5ts.dll,libmysql.dll 拷到 系統目錄(system/system32)
3.配置apache
步驟:(1)打開 d:\phpWeb\APACHE\conf\httpd.conf 這個文件
(2)找到 DocumentRoot "D:/phpWeb/APACHE/htdocs" 將其改為你的WEB目錄(可不改有時改了會出錯)
(3)找到DirectoryIndex index.html這一行,在後面加入index.html.var index.htm index.php
(4)找到#LoadMole ssl_mole moles/mod_ssl.so這行,在後面加上一行:LoadMole php5_mole d:/phpWeb/php/php5apache2_2.dll
(5)找到AddType application/x-gzip .gz .tgz這行,在後面加上一行:AddType application/x-httpd-php .php
4.配置php
步驟:(1)找到c:\windows\php.ini並打開 (剛才拷進去的)
(2)找到extension_dir = "./" 改為 extension_dir = "d:/phpWeb/php/ext"
(3)找到;extension=php_mysql.dll將前面的;號去掉
(4)找到;session.save_path = 去掉前面;並設路徑"d:/phpWeb/php/session_temp"並在該路徑下新建文件夾session_temp
㈧ struts2國際化的問題,如何把該語言設置為默認.如何在session中保存這個信息
呃,國際化本來就是根據自己計算機的地點知道語言的,你要這樣的話只有寫一個屬性在配置文件,假設設定當前語言是英語,然後在伺服器啟動的時候讀取配置文件修改當前地區為英語地區
㈨ 如何實現Spring MVC國際化的設置
一、基於瀏覽器語言的國際化配置 使用Spring的MVC,並且配置中有配置Resource文件 Xml代碼 以下是引用片段: 其中,message-info是你的properties文件的通用名。如:我的配置文件叫 message-info.properties,message-info_zh_CN.properties等等,只要有了這個配置,然後配置JSP 渲染器為JSTL支持的,那麼在你的JSP文件中使用fmt標記就可以實現客戶瀏覽器語言國際化了。 如: 以下是引用片段: 其中的info.login.title和你的資源文件對應. 另外一種方式是使用spring自帶的標簽顯示國際化信息,如: 以下是引用片段:
"/>
二、基於動態載入的國際化配置 1、基於請求的國際化配置 基於請求的國際化配置是指,在當前請求內,國際化配置生效,否則自動以瀏覽器為主。 配置方式如下: 首先配置攔截器 以下是引用片段: 這個配置呢,是不論請求級別的國際化,還是Cookie級別的國際化,再或者Session級別的國際化,都必需有配置這個攔截器,否則會不能使用。 配好上面的攔截器之後,就將攔截器注入到你的UrlHandlerMapping中,例如: Xml代碼 以下是引用片段: 1 這個時候,但凡有了符合UrlMapping的請求,就會被攔截,並且開始配置國際化參數 以下是引用片段: 默認的參數名為locale主意大小寫。裡面放的就是你的提交參數。如:en_US,zh_CN之類的,這個時候,你在頁面上加一句簡體中文 如果你的資源中,飽含建議中文的配置,那麼就會變成你確定的簡體中文拉。 2、基於Session的國際化配置 攔截器和基於請求的相同 Session的配置如下: 以下是引用片段: 在你的處理的Controller中,將提交上來的locale欄位信息生成真正的Locale對象,然後將對象保存在Session中,默認保存的ID是SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME 這樣,當你的Session不過期,那麼語言種類始終保持正確的說。我一直是這樣子用的,我覺得還是Session的好,老外們用了很滿意。 3、基於Cookie的國際化配置 這個我就不說了,反正用的不多,至少我做的項目能不用Cookie就不用Cookie,所以,基於Cookie的國際化配置我就不細說了,如果想知道怎麼配置,那麼下載一個Spring,其中的例子程序就是用Cookie配置的,你自己讀代碼就OK了。 三、注意事項 如果不用默認的瀏覽器語言國際化方式,那麼攔截器一定要配置,如果你有多個UrlMapping,那麼就每個都配上攔截器。 至於配置的LocaleResolver的名字,一定要用上面的配置中的名字localeResolver當然了,這個是默認的名字來的,自己設置成別的也可以,但是就是麻煩,反正我用默認的就感覺不錯 解決問題: 在前幾天引用「Spring的MVC I18N-國際化相關配置 」並做了測試,發現 有一問題。程序運行會拋出異常 「Cannot change HTTP accept header - use a different locale resolution strategy」,根本原因是spring source 做了限制,源碼如下 Java代碼 以下是引用片段: public class AcceptHeaderLocaleResolver implements LocaleResolver { public Locale resolveLocale(HttpServletRequest request) { return request.getLocale(); } public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) { throw new UnsupportedOperationException( "Cannot change HTTP accept header - use a different locale resolution strategy"); } } 請注意上面的類,該類允許繼承,所以需要改寫setLocale方法,源碼示範如下 Java代碼 以下是引用片段: package org.springframework.web.servlet.i18n; import java.util.Locale; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.LocaleResolver; public class MyAcceptHeaderLocaleResolver extends AcceptHeaderLocaleResolver { private Locale myLocal; public Locale resolveLocale(HttpServletRequest request) { return myLocal; } public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) { myLocal = locale; } } 然後在action-servlet.xml里的設置為 Xml代碼 以下是引用片段: chinese.do=filenameController us.do=filenameController