㈠ 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