はい、それを達成することはできますが、サーブレットを使用することはできません。必要なのは、以下のようなすべての共通メソッドと変数を保持するCommonクラスを定義することです。
public class Common {
public static final String DEFAULT_LANGUAGE = "en"; //better to have private variables with public setters and getters
....
public static String getDateFormatted(.....) {...}
....
}
データベースの相互作用を制御するために、別のデータベースクラスを作成することをお勧めします。まあ言ってみれば:
public class DBConnection {
private Connection dbCon;
//its more convenient to implement the connect on the no ArgumentCostructor
....
public boolean connect() throws ClassNotFoundException, SQLException {...}
public ResultSet execSQL(...)throws ClassNotFoundException,SQLException {...}
}
Javaクラス内からグローバルパラメータを使用する場合は、
String formatedDate = Common.getDateFormatted(date);
または、db接続に関するものについては呼び出すことができます
DBConnection con = new new DBConnection ();
rs = con.execSQL(sql);