I have code that is related to connection pool. Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/myoracle"); conn = ds.getConnection(); Many of struts's action need call it. I know 2 ways. 1) Codes is written in every action that use it. 2) encapsulating code into one class's static method.then every action class all call the class'static method using 1), I fell CODE is redundancy! using 2), when many user access application,if encapsulating class is single thread, performance will be bad. or,if I have other choice? Thanks [note]: Basically I Don't intend to use mutiple-tie structure,so I directly wirte sql into action class
Liang, You should try to avoid code redundancy as much as possible. A third alternative is to put the common code in an action superclass which your actions all extend. The new action would extend struts' action class. A fourth alternative is to put all the data access code in a separate class. The action could instantiate this class and call it. There isn't a need to rely on a static method.