亚洲三级电影网站,亚洲成av人在线视,亚洲天天做日日做天天欢毛片http://www.tkk7.com/hijeff/zh-cnSun, 11 May 2025 06:14:22 GMTSun, 11 May 2025 06:14:22 GMT60自定義RequestProcessorhttp://www.tkk7.com/hijeff/archive/2007/04/09/109478.htmlhijeffhijeffMon, 09 Apr 2007 10:52:00 GMThttp://www.tkk7.com/hijeff/archive/2007/04/09/109478.htmlhttp://www.tkk7.com/hijeff/comments/109478.htmlhttp://www.tkk7.com/hijeff/archive/2007/04/09/109478.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/109478.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/109478.html在Struts1.1-1.2中如果不想沒有登錄的用戶訪問一些action,可以擴展RequestProcessor,并重載processProprocess方法,在其中進行驗證

public class CustomRequestProcessor
        extends RequestProcessor {
    protected boolean processPreprocess (
            HttpServletRequest request,
            HttpServletResponse response) {
        HttpSession session = request.getSession(false);
        //If user is trying to access login page
        // then don't check
        if( request.getServletPath().equals("/loginInput.do")
            || request.getServletPath().equals("/login.do") )
            return true;
        //Check if userName attribute is there is session.
        //If so, it means user has allready logged in
        if( session != null &&
        session.getAttribute("userName") != null)
            return true;
        else{
            try{
                //If no redirect user to login Page
                request.getRequestDispatcher 
                    ("/Login.jsp").forward(request,response);
            }catch(Exception ex){
            }
        }
        return false;
    }
}

相應的,在struts-config.xml中加入controller元素

<controller>
 <set-property  property="processorClass"
 value="com.sample.util.CustomRequestProcessor"/>
</controller>

但剛才看到在Struts1.3中,已經不再使用RequestProcessor,而是用ComposableRequestProcessor 來實現自定義的request響應。








hijeff 2007-04-09 18:52 發表評論
]]>
Ternary association & Queryhttp://www.tkk7.com/hijeff/archive/2007/04/02/108020.htmlhijeffhijeffMon, 02 Apr 2007 09:45:00 GMThttp://www.tkk7.com/hijeff/archive/2007/04/02/108020.htmlhttp://www.tkk7.com/hijeff/comments/108020.htmlhttp://www.tkk7.com/hijeff/archive/2007/04/02/108020.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/108020.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/108020.html三個@Entity類Tc, Tracer, Track是三向關聯的的表, @Embeddable類TcTracer則存儲著三個表的ForeignKey

@Entity
@Table(name= "tc", catalog="first_hiber")
public class Tc {
      @org.hibernate.annotations.CollectionOfElements
      @JoinTable(name="tc_tracer", joinColumns=@JoinColumn(name="tc_id"))
      private Set<TcTracer> tcTracers = new HashSet<TcTracer>();

      @Id @GeneratedValue
      @Column(name="tc_id", nullable= false)
      private Long id;
}
  @Embeddable
  @Table(name="tc_tracer")
  public class TcTracer {
      @org.hibernate.annotations.Parent
      private Tc tc;
  
@ManyToOne(cascade=CascadeType.ALL) @JoinColumn(name="tracer_id", nullable=false, updatable=false) private Tracer tracer; @ManyToOne(cascade=CascadeType.ALL) @JoinColumn(name="track_id", nullable=false, updatable=false) private Track track; }

如上,將TcTracer作為Tc的子元素,從而實現Tc的三相關聯。

用HQL可以通過特定的Tc,Tracer得到對應的所有Track:

  select tctracers.track
  from Tc tc
      join tc.tcTracers tctracers
  where tc.name="tc name"
      and tctracers.tracer.name="tracer name"
 List<Track> tracks = session.createQuery(HQL).list();


hijeff 2007-04-02 17:45 發表評論
]]>
今天遇到一個用Annotation設置mapping的錯誤....http://www.tkk7.com/hijeff/archive/2007/03/29/107323.htmlhijeffhijeffThu, 29 Mar 2007 12:28:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/29/107323.htmlhttp://www.tkk7.com/hijeff/comments/107323.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/29/107323.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/107323.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/107323.html今天調試程序的時候,發現插入數據時老是拋出異常:"a different object with the same identifier value was already associated with the session"

起初以為是override hashCode()的方法不對。后來google查了查多數問題都出現在detached對象之后,再鏈接session由于對象的改變而出現的異常。

最后發現原來問題很簡單....是在用annotation重寫mapping的時候,忘記給@Id加上@GeneratedValue,導致第一個row insert后,再次insert時沒有生成新的id!

看來annotation雖然方便了mapping,但由于和代碼集中在一塊了,很容易出現疏忽大意的錯誤,而且一般都不會注意到-.-

想起了python的SQLObject, SQLAlchemy,雖然功能沒有Hibernate豐富,但是簡單實用!



hijeff 2007-03-29 20:28 發表評論
]]>
Define Bi-directional Association with Annotationhttp://www.tkk7.com/hijeff/archive/2007/03/27/106766.htmlhijeffhijeffTue, 27 Mar 2007 13:18:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/27/106766.htmlhttp://www.tkk7.com/hijeff/comments/106766.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/27/106766.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/106766.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/106766.html通常為了實現entity class的雙向association,每添加一組實例在java中需要兩行代碼:

persion.getAddresses().add(address);
address.getPersons().add(person);

但對Hibernate而已,上面的代碼會被轉化為兩條insert語句,

為了避免這樣的情況出現需要定義inverse屬性,告訴Hibernate persion和address之間的關系:

// !file: Person.class
public class Person {
    // ...
    @ManyToMany(
              targetEntity= Address.class,
              cascade = CascadeType.ALL,
      )
    @JoinTable(
              name="persion_address",
              joinColumns= {@JoinColumn(name="person_id")},
              inverseJoinColumns= {@JoinColumn(name="address_id")}
      )
      private Set<Address> adressses = new HashSet<Address> (0);
    // ...
}
// !file: Address.class
public class Address {
    // ...
    @ManyToMany(
            targetEntity= Persion.class,
            cascade = CascadeType.ALL, 
            mappedBy = "addresses"
    )
    private Set<Person> persons = new HashSet<Person>();
    // ...
}

上面的兩個annotation告訴Hibernate,Person是主,對Address中persons屬性的修改將不會產生SQL語句。

Hibernate里,如果是Many-to-many的關系,可以任意設置主class。

通常,還可以將添加刪除關系的代碼包裝起來:

// !file: Person.class
public class Person {
    // ...
    public void addAddress(Address address) {
        this.getAddresses().add(address);
        address.getPersons().add(this);
    }
    public void removeAddress(Address address) {
        this.getAddresses().remove(address);
        address.getPersons().remove(this);
    }
    //...
} 





hijeff 2007-03-27 21:18 發表評論
]]>
Manning - Java Persistence with Hibernate 的下載http://www.tkk7.com/hijeff/archive/2007/03/23/105698.htmlhijeffhijeffFri, 23 Mar 2007 00:21:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/23/105698.htmlhttp://www.tkk7.com/hijeff/comments/105698.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/23/105698.html#Feedback7http://www.tkk7.com/hijeff/comments/commentRss/105698.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/105698.htmlhttp://www.box.net/shared/102b5irypc

差不多把平時用的上的讀完了,真感覺受益匪淺。不但詳細的介紹了Hibernate的特性用法,而且其中介紹的ORM基本概念,灌輸的ORM的思想也正是我所需要的。

對一個新手來說,business key, surrogate key, entity type, value type, transient, persistent, detached, persistence context...這些是什么概念,為什么要提出來,以及怎樣實現的在書中都會有簡單明了的解釋。

不多說了,現在把書放出來,誰看誰知道;)



hijeff 2007-03-23 08:21 發表評論
]]>
使用 SchemaExport 自動建表http://www.tkk7.com/hijeff/archive/2007/03/21/105125.htmlhijeffhijeffTue, 20 Mar 2007 16:56:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/21/105125.htmlhttp://www.tkk7.com/hijeff/comments/105125.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/21/105125.html#Feedback4http://www.tkk7.com/hijeff/comments/commentRss/105125.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/105125.html之前都是用最蠢的方法:SQL建立數據庫相關的表,然后再Java寫映射寫配置文件.....

實際上使用Hibernate自帶的工具hbm2ddl,建立根據你的對象建立數據庫是很愜意的一件事;)

首先當然要建好POJO object, XML Mapping File(也可以使用工具根據POJO class建立),配置文件(hibernate.cfg.xml)

然后運行下面的Java代碼


import org.hibernate.cfg.Configuration; 
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class SchemaUtil {
public static void main(String[] args) {

Configuration cfg = new Configuration().configure(); SchemaExport schemaExport= new SchemaExport(cfg); schemaExport.create(false, true); } }
再看看數據庫,表是不是已經幫你建好了,對于我這樣不熟悉數據庫的人真是太方便了

Technorati : , , ,
Del.icio.us : , , ,



hijeff 2007-03-21 00:56 發表評論
]]>
<Java Persistence With Hibernate> 是本好書http://www.tkk7.com/hijeff/archive/2007/03/20/105107.htmlhijeffhijeffTue, 20 Mar 2007 14:14:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/20/105107.htmlhttp://www.tkk7.com/hijeff/comments/105107.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/20/105107.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/105107.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/105107.html內容詳實,通俗易懂

決定花幾天時間好好的讀讀這本書,系統的學習Hibernate。

Technorati : , ,
Del.icio.us : , ,



hijeff 2007-03-20 22:14 發表評論
]]>
將數組轉化成Collection類http://www.tkk7.com/hijeff/archive/2007/03/17/104514.htmlhijeffhijeffSat, 17 Mar 2007 13:58:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/17/104514.htmlhttp://www.tkk7.com/hijeff/comments/104514.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/17/104514.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/104514.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/104514.html Set set = new HashSet(Arrays.asList(array));

hijeff 2007-03-17 21:58 發表評論
]]>
Web程序中的字符編碼問題http://www.tkk7.com/hijeff/archive/2007/03/15/104089.htmlhijeffhijeffThu, 15 Mar 2007 12:58:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/15/104089.htmlhttp://www.tkk7.com/hijeff/comments/104089.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/15/104089.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/104089.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/104089.htmlWeb程序的編碼問題主要有三個方面:

  1. 程序文件的編碼;
  2. 輸出頁面到客戶端的編碼;
  3. 用戶響應到服務器端的編碼。

以設置為UTF-8為例,可以用如下方法解決。

1. 對于程序文件的編碼

直接在Eclipse或者其他IDE,editor中將文件編碼設為UTF-8即可。

2.輸出頁面

對于JSP頁面,加入以下代碼

<%@ page contentType="text/html; charset=UTF-8"%>
如果在IE或者Firefox中還不能正常顯示,還可以在Html標識下加入下面的頭信息

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

3. 響應到服務器端

我使用的是Tomcat,沒有可以直接設置接受響應編碼的方法(真是太佩服了!),但可以通過寫一個Filter實現編碼轉化。

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class SetCharacterEncodingFilter implements Filter {

    protected String encoding = null;
    protected FilterConfig filterConfig = null;
    protected boolean ignore = true;

    public void destroy() {
        this.encoding = null;
        this.filterConfig = null;
    }

    public void doFilter(ServletRequest request, ServletResponse response,
                          FilterChain chain)
        throws IOException, ServletException {
        if (ignore || (request.getCharacterEncoding() == null)) {
            String encoding = selectEncoding(request);
            if (encoding != null)
                request.setCharacterEncoding(encoding);
        }
        chain.doFilter(request, response);
    }

    public void init(FilterConfig filterConfig) throws ServletException {
     this.filterConfig = filterConfig;
        this.encoding = filterConfig.getInitParameter("encoding");
        String value = filterConfig.getInitParameter("ignore");
        if (value == null)
            this.ignore = true;
        else if (value.equalsIgnoreCase("true"))
            this.ignore = true;
        else if (value.equalsIgnoreCase("yes"))
            this.ignore = true;
        else
            this.ignore = false;
    }

    protected String selectEncoding(ServletRequest request) {
        return (this.encoding);
    }
}

將SetCharacterEncodingFilter放到程序的編譯目錄下,再在web.xml中添加相應屬性


    <filter>
        <filter-name>Set Character Encoding</filter-name>
        <filter-class>hijeff.filters.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
     
    <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>    

Tomcat就會將用戶通過HTTP響應的字符轉化為UTF-8的編碼了




hijeff 2007-03-15 20:58 發表評論
]]>
Hibernate的四種配置方法http://www.tkk7.com/hijeff/archive/2007/03/13/103472.htmlhijeffhijeffTue, 13 Mar 2007 02:54:00 GMThttp://www.tkk7.com/hijeff/archive/2007/03/13/103472.htmlhttp://www.tkk7.com/hijeff/comments/103472.htmlhttp://www.tkk7.com/hijeff/archive/2007/03/13/103472.html#Feedback0http://www.tkk7.com/hijeff/comments/commentRss/103472.htmlhttp://www.tkk7.com/hijeff/services/trackbacks/103472.htmlvia

  1. Pass an instance of java.util.Properties to Configuration.setProperties().
  2. Place hibernate.properties in a root directory of the classpath.
  3. Set System properties using java -Dproperty=value.
  4. Include <property> elements in hibernate.cfg.xml .



hijeff 2007-03-13 10:54 發表評論
]]>
主站蜘蛛池模板: 免费在线看片网站| 亚洲国模精品一区| 亚洲欧洲国产精品久久| 国产高清不卡免费视频| 亚洲成av人片在线观看无码不卡| 国产黄色免费观看| 精品亚洲一区二区| 99久久免费看国产精品| 久久狠狠高潮亚洲精品| 五月婷婷在线免费观看| 精品丝袜国产自在线拍亚洲| 免费观看的av毛片的网站| 春暖花开亚洲性无区一区二区 | 福利片免费一区二区三区| 国产精品公开免费视频| 免费视频精品一区二区| 亚洲日本乱码在线观看| 最近免费中文字幕mv在线电影| 2019亚洲午夜无码天堂| 性做久久久久免费看| 久久av免费天堂小草播放| 亚洲午夜视频在线观看| 免费精品人在线二线三线区别| 亚洲av永久无码天堂网| 亚洲福利中文字幕在线网址| 二区久久国产乱子伦免费精品| 亚洲va在线va天堂va不卡下载 | 无码人妻精品中文字幕免费| 亚洲国产成人精品无码区在线秒播 | 久久亚洲高清综合| 四虎影视成人永久免费观看视频 | 亚洲国产精品成人网址天堂| 在线观看人成视频免费无遮挡 | 羞羞漫画小舞被黄漫免费| 亚洲国产精品ⅴa在线观看| 在线观看91精品国产不卡免费| 亚洲AV无码之国产精品| 一本色道久久综合亚洲精品高清| 先锋影音资源片午夜在线观看视频免费播放| 亚洲精品午夜视频| 亚洲精品国产成人影院|