02 2012 档案

摘要:slf是hibernate提供的一个日志接口,它可以被log4j,JDK的日志或则slf自己的日志 去实现。使用方式:在开发过程中统一按照slf4j的API进行开发,在部署的时候,选择不同的日志系统包(包括配置文件),即可自动转换到不同的日志系统上。比如:选择JDK自带的日志系统,则只需要将slf4j-api-1.6.4.jar和slf4j-jdk14-1.6.4.jar放置到classpath中即可,如果中途无法忍受JDK自带的日志系统了,想换成log4j的日志系统,仅需要用slf4j-log4j12-1.6.4.jar替换slf4j-jdk14-1.5.10.jar即可。#使用时将log4 阅读全文
posted @ 2012-02-29 11:52 濤叔 阅读(1243) 评论(0) 推荐(0)
摘要:hibernate通过sessionFactory有两种方式获取session:一种是openSession,一种是getCurrentSessionopenSession创建session时autoCloseSessionEnabled参数为false,即在事物结束后不会自动关闭session,需要手动关闭,如果不关闭将导致session关联的数据库连接无法释放,最后资源耗尽而使程序当掉。getCurrentSession创建session时autoCloseSessionEnabled,flushBeforeCompletionEnabled都为true,并且session会同sessio 阅读全文
posted @ 2012-02-29 11:22 濤叔 阅读(1837) 评论(0) 推荐(0)
摘要:官方在线参考文档:http://docs.jboss.org/hibernate/core/3.6/reference/zh-CN/html_single/此复习笔记的对应文档:http://docs.jboss.org/hibernate/core/3.3/reference/zh-CN/html_single/ 中间数字为版本信息。一、创建实体类字段和数据库表中字段的一一对应。Event.javaView Code import java.util.Date;public class Event { private Long id; private String title; ... 阅读全文
posted @ 2012-02-27 19:21 濤叔 阅读(1382) 评论(0) 推荐(0)
摘要:自定义拦截器:自定义拦截器可以处理 敏感词汇等。AOP的一个体现。实现Interceptor接口,重写intercept方法,invocation.invoke()会循环调用。View Code import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.Interceptor;public class MyInterceptor implements Interceptor { public void destroy() { // TODO Auto-... 阅读全文
posted @ 2012-02-26 16:07 濤叔 阅读(282) 评论(0) 推荐(0)
摘要:struts.xml<constant name="struts.custom.i18n.resources" value="app"></constant>资源文件的名称为 app_*_*.propertiesapp_en_US.propertiesView Code login.username=username:login.password=password:login.login=loginwelcome.msg=welcome:{0}app_zh_CN.propertiesView Code login.username 阅读全文
posted @ 2012-02-26 13:57 濤叔 阅读(195) 评论(0) 推荐(0)
摘要:创建配置文件:格式 文件名_语言_国家.properties (文件名后面都是固定的),如:app_en_US.propertiesapp_zh_CN.propertiesJAVA调用文件:View Code public static void main(String[] args) { ResourceBundle res = ResourceBundle.getBundle("app", Locale.CHINA); System.out.println(res.getString("welcome.msg" )); }会自动调用 app_zh_C 阅读全文
posted @ 2012-02-26 12:27 濤叔 阅读(339) 评论(0) 推荐(0)
摘要:所有异常不在action中处理,全部抛出。然后在struts.xml中进行处理。struts.xmlView Code <action name="*-*" class="com.bjsxt.bbs2009.action.{1}Action" method="{2}"> <result>/admin/{1}-{2}.jsp</result> <result name="input">/admin/{1}-{2}.jsp</result> <excep 阅读全文
posted @ 2012-02-26 11:37 濤叔 阅读(205) 评论(0) 推荐(0)
摘要:原文地址:http://www.tracefact.net/CSharp-Programming/Delegates-and-Events-in-CSharp.aspx引言委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易。它们就像是一道槛儿,过了这个槛的人,觉得真是太容易了,而没有过去的人每次见到委托和事件就觉得心里别(biè)得慌,混身不自在。本文中,我将通过两个范例由浅入深地讲述什么是委托、为什么要使用委托、事件的由来、.Net Framework中的委托和事件、委托和事件对Observer设计模式的 阅读全文
posted @ 2012-02-24 17:15 濤叔 阅读(167) 评论(0) 推荐(0)
摘要:一.property标签View Code <!-- 输出username元素 --> <li>property: <s:property value="username"/> </li> <!-- 输出字符串'username' --> <li>property 取值为字符串: <s:property value="'username'"/> </li> <!-- 找不到admin就赋值默认值 --> <li 阅读全文
posted @ 2012-02-23 18:09 濤叔 阅读(245) 评论(0) 推荐(0)
摘要:一、使用OGNL访问对象 1 读取struts2中的ValueStack中的值 struts2中引入了ValueStack的概念,在struts2中默认使用ValueStack作为OGNL的StackContext的根元素 OGNL在读取根元素的时候能够直接进行读取 假设action中有 private Cat cat; private Dog dog; 俩个对象,那么在jsp页面读取方法就是 <s:property value="cat.name"/> 读取Cat的name属性的值 <s:property value="dog.name&quo 阅读全文
posted @ 2012-02-23 17:41 濤叔 阅读(1051) 评论(0) 推荐(0)
摘要:在struts.xml中<result type="redirect">/user_success.jsp?t=${type}</result>View Code public class UserAction extends ActionSupport { private int type; public int getType() { return type; } public void setType(int type) { this.type = type; } @Override public String... 阅读全文
posted @ 2012-02-23 16:19 濤叔 阅读(205) 评论(0) 推荐(0)
摘要:struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <action name="user" class="com.bjsxt.struts2.user.action.UserAction" 阅读全文
posted @ 2012-02-23 16:13 濤叔 阅读(247) 评论(0) 推荐(0)
摘要:View Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" namespace="/user" extends="struts-default"> <global-results> <result name="mainpage">/main.jsp</result> </global- 阅读全文
posted @ 2012-02-23 16:04 濤叔 阅读(533) 评论(0) 推荐(0)
摘要:Result类型dispatcherredirectchainredirectActionfreemarkerhttpheaderstreamvelocityxsltplaintexttilesstruts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="resultTypes" namespace="/r" extends="struts-default 阅读全文
posted @ 2012-02-23 15:36 濤叔 阅读(300) 评论(0) 推荐(0)
摘要:在访问不存在的页面或action的时候,可以设置跳到首页。struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/" extends="struts-default"> <default-action-ref name="index"></default- 阅读全文
posted @ 2012-02-23 15:04 濤叔 阅读(193) 评论(0) 推荐(0)
摘要:struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <include file="login.xml" /></struts>login.xmlView Code <struts> <package name="login" extends="struts-default" namespace="/login" 阅读全文
posted @ 2012-02-23 15:01 濤叔 阅读(209) 评论(0) 推荐(0)
摘要:有四种方法可以得到request session application等web元素。方法一LoginAction1.javaView Code public class LoginAction1 extends ActionSupport { private Map request; private Map session; private Map application; public LoginAction1() { request = (Map)ActionContext.getContext().get("request"); ... 阅读全文
posted @ 2012-02-22 23:13 濤叔 阅读(332) 评论(0) 推荐(1)
摘要:UserAction.javaView Code public class UserAction extends ActionSupport { private String name; public String add() { if(name == null || !name.equals("admin")) { this.addFieldError("name", "name is error"); this.addFieldError("name", "name is too long" 阅读全文
posted @ 2012-02-22 15:20 濤叔 阅读(263) 评论(0) 推荐(0)
摘要:在struts.xml中配置字符处理。struts.xmlView Code <struts> <constant name="struts.i18n.encoding" value="GBK" /> <!-- internationalization --> </package></struts>即可转换字符编码。但是在struts2.1.6中存在BUG。需要在WEB.XML重新配置以个过滤器,换成2.0的配置。或则手动配置filter,还可以用spring的filter。View Code 阅读全文
posted @ 2012-02-22 13:54 濤叔 阅读(183) 评论(0) 推荐(0)
摘要:UserAction.javaView Code import com.bjsxt.struts2.user.model.User;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.ModelDriven;public class UserAction extends ActionSupport implements ModelDriven<User>{ private User user = new User(); public String add() { ... 阅读全文
posted @ 2012-02-22 13:31 濤叔 阅读(247) 评论(0) 推荐(0)
摘要:DomaimModel域模型 就是将参数封装成 dto 对象。struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" extends="struts-default" namespace="/user"> <action name="user" class="com.bjsxt.stru 阅读全文
posted @ 2012-02-22 11:29 濤叔 阅读(505) 评论(0) 推荐(0)
摘要:struts.xmlView Code <struts> <constant name="struts.devMode" value="true" /> <package name="user" extends="struts-default" namespace="/user"> <action name="user" class="com.bjsxt.struts2.user.action.UserAction" 阅读全文
posted @ 2012-02-22 11:14 濤叔 阅读(328) 评论(0) 推荐(0)
摘要:struts.xmlView Code <package name="actions" extends="struts-default" namespace="/actions"> <action name="Student*" class="com.bjsxt.struts2.action.StudentAction" method="{1}"> <result>/Student{1}_success.jsp</result> 阅读全文
posted @ 2012-02-21 23:51 濤叔 阅读(210) 评论(0) 推荐(0)
摘要:Action执行的时候并不一定要执行execute方法可以在配置文件中配置Action的时候用method=来指定执行哪个方法也可以在url地址中动态指定(动态方法调用DMI)(推荐)前者会产生太多的action,所以不推荐使用struts.xmlView Code <action name="userAdd" class="com.bjsxt.struts2.user.action.UserAction" method="add"> <result>/user_add_success.jsp</resu 阅读全文
posted @ 2012-02-21 23:41 濤叔 阅读(284) 评论(0) 推荐(0)
摘要:struts2中的路径问题是根据action的路径而不是jsp路径来确定,所以尽量不要使用相对路径。虽然可以用redirect方式解决,但redirect方式并非必要。 解决办法非常简单,统一使用绝对路径。(在jsp中用request.getContextRoot方式来拿到webapp的路径) 或者使用myeclipse经常用的,指定basePathstruts.xmlView Code <constant name="struts.devMode" value="true" /> <package name="path&qu 阅读全文
posted @ 2012-02-21 23:18 濤叔 阅读(326) 评论(0) 推荐(0)
摘要:具体视图的返回可以由用户自己定义的Action来决定具体的手段是根据返回的字符串找到对应的配置项,来决定视图的内容具体Action的实现可以是一个普通的java类,里面有public String execute方法即可或者实现Action接口不过最常用的是从ActionSupport继承,好处在于可以直接使用Struts2封装好的方法struts.xmlView Code <constant name="struts.devMode" value="true" /> <package name="front" ex 阅读全文
posted @ 2012-02-21 22:49 濤叔 阅读(321) 评论(0) 推荐(0)
摘要:namespace决定了action的访问路径,默认为"",可以接收所有路径的actionnamespace可以写为/,或者/xxx,或者/xxx/yyy,对应的action访问路径为/index.action, /xxx/index.action,或者/xxx/yyy/index.action.namespace最好也用模块来进行命名View Code <constant name="struts.devMode" value="true" /> <package name="front" ex 阅读全文
posted @ 2012-02-21 22:30 濤叔 阅读(258) 评论(0) 推荐(0)
摘要:1.添加struts2支持包到lib目录下。2.创建struts.xml文件并放到src目录下。View Code <?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts> 阅读全文
posted @ 2012-02-21 21:50 濤叔 阅读(300) 评论(0) 推荐(0)