Hey,buddy:What's up?

          Happy&Optimistic&Effective

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            14 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

          2006年4月27日 #

          本程序改變自網上的一個datapicker,沒有用javax包,而是基于java.awt包。you can use it in your applet.共四個文件。

          //1.AbsoluteConstraints.java

          import java.awt.Dimension;
          import java.awt.Point;

          public class AbsoluteConstraints
          ??? implements java.io.Serializable {
          ? static final long serialVersionUID = 5261460716622152494L;
          ? public int x;
          ? public int y;
          ? public int width = -1;
          ? public int height = -1;
          ? public AbsoluteConstraints(Point pos) {
          ??? this(pos.x, pos.y);
          ? }

          ? public AbsoluteConstraints(int x, int y) {
          ??? this.x = x;
          ??? this.y = y;
          ? }

          ? public AbsoluteConstraints(Point pos, Dimension size) {
          ??? this.x = pos.x;
          ??? this.y = pos.y;
          ??? if (size != null) {
          ????? this.width = size.width;
          ????? this.height = size.height;
          ??? }
          ? }

          ? public AbsoluteConstraints(int x, int y, int width, int height) {
          ??? this.x = x;
          ??? this.y = y;
          ??? this.width = width;
          ??? this.height = height;
          ? }

          ? public int getX() {
          ??? return x;
          ? }

          ? public int getY() {
          ??? return y;
          ? }

          ? public int getWidth() {
          ??? return width;
          ? }

          ? public int getHeight() {
          ??? return height;
          ? }

          ? public String toString() {
          ??? return super.toString() + " [x=" + x + ", y=" + y + ", width=" + width +
          ??????? ", height=" + height + "]";
          ? }
          }



          //2.import java.awt.*;

          public class AbsoluteLayout
          ??? implements LayoutManager2, java.io.Serializable {
          ? static final long
          ????? serialVersionUID = -1919857869177070440L;
          ? protected java.util.Hashtable constraints = new java.util.Hashtable();
          ? public
          ????? void addLayoutComponent(String name, Component comp) {
          ??? throw new IllegalArgumentException();
          ? }

          ? public void
          ????? removeLayoutComponent(Component comp) {
          ??? constraints.remove(comp);
          ? }

          ? public Dimension preferredLayoutSize
          ????? (Container parent) {
          ??? int maxWidth = 0;
          ??? int maxHeight = 0;
          ??? for (java.util.Enumeration e =
          ???????? constraints.keys(); e.hasMoreElements(); ) {
          ????? Component comp = (Component) e.nextElement();
          ????? AbsoluteConstraints
          ????????? ac = (AbsoluteConstraints) constraints.get(comp);
          ????? Dimension size = comp.getPreferredSize();
          ????? int width =
          ????????? ac.getWidth();
          ????? if (width == -1)
          ??????? width = size.width;
          ????? int height = ac.getHeight();
          ????? if (height == -1)
          ??????? height = size.height;
          ????? if (ac.x + width > maxWidth)
          ??????? maxWidth = ac.x + width;
          ????? if (ac.y + height >
          ????????? maxHeight)
          ??????? maxHeight = ac.y + height;
          ??? }
          ??? return new Dimension(maxWidth, maxHeight);
          ? }

          ? public
          ????? Dimension minimumLayoutSize(Container parent) {
          ??? int maxWidth = 0;
          ??? int maxHeight = 0;
          ??? for
          ??????? (java.util.Enumeration e = constraints.keys(); e.hasMoreElements(); ) {
          ????? Component comp = (Component) e.nextElement();
          ????? AbsoluteConstraints ac = (AbsoluteConstraints) constraints.get(comp);
          ????? Dimension size = comp.getMinimumSize();
          ????? int width = ac.getWidth();
          ????? if (width == -1)
          ??????? width = size.width;
          ????? int height = ac.getHeight();
          ????? if (height == -1)
          ??????? height = size.height;
          ????? if (ac.x + width > maxWidth)
          ??????? maxWidth = ac.x + width;
          ????? if
          ????????? (ac.y + height > maxHeight)
          ??????? maxHeight = ac.y + height;
          ??? }
          ??? return new Dimension(maxWidth, maxHeight);
          ? }

          ? public void layoutContainer(Container parent) {
          ??? for (java.util.Enumeration e = constraints.keys();
          ???????? e.hasMoreElements(); ) {
          ????? Component comp = (Component) e.nextElement();
          ????? AbsoluteConstraints ac =
          ????????? (AbsoluteConstraints) constraints.get(comp);
          ????? Dimension size = comp.getPreferredSize();
          ????? int width = ac.getWidth();
          ????? if (width == -1)
          ??????? width = size.width;
          ????? int height = ac.getHeight();
          ????? if (height == -1)
          ??????? height = size.height;
          ????? comp.setBounds(ac.x, ac.y, width, height);
          ??? }
          ? }

          ? public void addLayoutComponent
          ????? (Component comp, Object constr) {
          ??? if (! (constr instanceof AbsoluteConstraints))
          ????? throw new
          ????????? IllegalArgumentException();
          ??? constraints.put(comp, constr);
          ? }

          ? public Dimension maximumLayoutSize(Container
          ???????????????????????????????????? target) {
          ??? return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
          ? }

          ? public float getLayoutAlignmentX
          ????? (Container target) {
          ??? return 0;
          ? }

          ? public float getLayoutAlignmentY(Container target) {
          ??? return 0;
          ? }

          ? public void invalidateLayout(Container target) {}
          }

          // 3DateField.java

          import java.awt.BorderLayout;
          import java.awt.Color;
          import java.awt.Insets;
          import java.awt.Point;
          import java.awt.event.ActionEvent;
          import java.awt.event.ActionListener;
          import java.awt.event.ComponentAdapter;
          import java.awt.event.ComponentEvent;
          import java.awt.event.MouseAdapter;
          import java.awt.event.MouseEvent;
          import java.awt.event.MouseMotionAdapter;
          import java.net.URL;
          import java.text.DateFormat;
          import java.text.ParseException;
          import java.util.Date;
          import java.awt.*;

          public final class DateField
          ??? extends Panel {
          ? private static final long serialVersionUID = 1L;
          ? private final TextField dateText = new TextField(12);
          ? private final Button dropdownButton = new Button();
          ? private DatePicker dp;
          ? private Dialog dlg;
          ? Point origin = new Point();
          ? final class Listener
          ????? extends ComponentAdapter {
          ??? public void componentHidden(final ComponentEvent evt) {
          ????? final Date dt = ( (DatePicker) evt.getSource()).getDate();
          ????? if (null != dt)
          ??????? dateText.setText(dateToString(dt));
          ????? dlg.dispose();
          ??? }
          ? }

          ? public DateField() {
          ??? super();
          ??? init();
          ? }

          ? public DateField(final Date initialDate) {
          ??? super();
          ??? init();
          ??? dateText.setText(dateToString(initialDate));
          ? }

          ? public Date getDate() {
          ??? return stringToDate(dateText.getText());
          ? }

          ? public void setDate(Date date) {
          ??? String v = dateToString(date);
          ??? if (v == null) {
          ????? v = "";
          ??? }
          ??? dateText.setText(v);
          ? }

          ? private void init() {
          ??? setLayout(new BorderLayout());
          ??? dateText.setText("");
          ??? dateText.setEditable(false);
          ??? dateText.setBackground(new Color(255, 255, 255));
          ??? add(dateText, BorderLayout.CENTER);
          ??? dropdownButton.setLabel("選擇");
          ??? dropdownButton.setBackground(Color.yellow);
          ??? dropdownButton.addActionListener(new ActionListener() {
          ????? public void actionPerformed(final ActionEvent evt) {
          ??????? onButtonClick(evt);
          ????? }
          ??? });
          ??? add(dropdownButton, BorderLayout.EAST);
          ? }

          ? private void onButtonClick(final java.awt.event.ActionEvent evt) {
          ??? if ("".equals(dateText.getText()))
          ????? dp = new DatePicker();
          ??? else
          ????? dp = new DatePicker(stringToDate(dateText.getText()));
          ??? dp.addComponentListener(new Listener());
          ??? final Point p = dateText.getLocationOnScreen();
          ??? p.setLocation(p.getX(), p.getY() - 1 + dateText.getSize().getHeight());
          ??? dlg = new Dialog(new Frame(), true);
          ??? dlg.addMouseListener(new MouseAdapter() {
          ????? public void mousePressed(MouseEvent e) {
          ??????? origin.x = e.getX();
          ??????? origin.y = e.getY();
          ????? }
          ??? });
          ??? dlg.addMouseMotionListener(new MouseMotionAdapter() {
          ????? public void mouseDragged(MouseEvent e) {
          ??????? Point p = dlg.getLocation();
          ??????? dlg.setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y);
          ????? }
          ??? });
          ??? dlg.setLocation(p);
          ??? dlg.setResizable(false);
          ??? dlg.setUndecorated(true);
          ??? dlg.add(dp);
          ??? dlg.pack();
          ??? dlg.setVisible(true);
          ? }

          ? private static String dateToString(final Date dt) {
          ??? if (null != dt)
          ????? return DateFormat.getDateInstance(DateFormat.LONG).format(dt);
          ??? return null;
          ? }

          ? private static Date stringToDate(final String s) {
          ??? try {
          ????? return DateFormat.getDateInstance(DateFormat.LONG).parse(s);
          ??? }
          ??? catch (ParseException e) {
          ????? return null;
          ??? }
          ? }

          ? public static void main(String[] args) {
          ??? Dialog dlg = new Dialog(new Frame(), true);
          ??? DateField df = new DateField();
          ?? //dlg.getContentPane().add(df);
          ?? dlg.add(df);
          ??? dlg.pack();
          ??? dlg.setVisible(true);
          ??? System.out.println(df.getDate().toString());
          ??? System.exit(0);
          ? }
          }

          //4.DatePicker.java

          import java.awt.*;
          import java.awt.event.*;
          import java.util.GregorianCalendar;
          import java.util.Date;
          import java.util.Calendar;
          import java.text.DateFormat;
          import java.text.FieldPosition;
          /*
          import javax.swing.*;
          import javax.swing.plaf.BorderUIResource;
          */
          public final class DatePicker
          ??? extends Panel {
          ? private static final long serialVersionUID = 1L;
          ? private static final int startX = 10;
          ? private static final int startY = 60;
          ? private static final Font smallFont = new Font("Dialog", Font.PLAIN, 10);
          ? private static final Font largeFont = new Font("Dialog", Font.PLAIN, 12);
          ? private static final Insets insets = new Insets(2, 2, 2, 2);
          ? private static final Color highlight = Color.YELLOW;//new Color(255, 255, 204);
          ? private static final Color white = new Color(255, 255, 255);
          ? private static final Color gray = new Color(204, 204, 204);
          ? private Component selectedDay = null;
          ? private GregorianCalendar selectedDate = null;
          ? private GregorianCalendar originalDate = null;
          ? private boolean hideOnSelect = true;
          ? private final Button backButton = new Button();
          ? private final Label monthAndYear = new Label();
          ? private final Button forwardButton = new Button();
          ? private final Label[] dayHeadings = new Label[] {
          ????? new Label("日"),
          ????? new Label("一"),
          ????? new Label("二"),
          ????? new Label("三"),
          ????? new Label("四"),
          ????? new Label("五"),
          ????? new Label("六")};

          ? private final Label[][] daysInMonth = new Label[][] {
          ????? {
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label()}
          ????? , {
          ????? new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label()}
          ????? , {
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label()}
          ????? , {
          ????? new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label()}
          ????? , {
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label()}
          ????? , {
          ????? new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label(),
          ????? new Label(), new Label()}
          ? };
          ? private final Button todayButton = new Button();
          ? private final Button cancelButton = new Button();
          ? public DatePicker() {
          ??? super();
          ??? selectedDate = getToday();
          ??? init();
          ? }

          ? public DatePicker(final Date initialDate) {
          ??? super();
          ??? if (null == initialDate)
          ????? selectedDate = getToday();
          ??? else
          ????? (selectedDate = new GregorianCalendar()).setTime(initialDate);
          ??? originalDate = new GregorianCalendar(selectedDate.get(Calendar.YEAR),
          ???????????????????????????????????????? selectedDate.get(Calendar.MONTH),
          ???????????????????????????????????????? selectedDate.get(Calendar.DATE));
          ??? init();
          ? }

          ? public boolean isHideOnSelect() {
          ??? return hideOnSelect;
          ? }

          ? public void setHideOnSelect(final boolean hideOnSelect) {
          ??? if (this.hideOnSelect != hideOnSelect) {
          ????? this.hideOnSelect = hideOnSelect;
          ????? initButtons(false);
          ??? }
          ? }

          ? public Date getDate() {
          ??? if (null != selectedDate)
          ????? return selectedDate.getTime();
          ??? return null;
          ? }

          ? private void init() {
          ??? setLayout(new AbsoluteLayout());
          ??? /*
          ??? this.setMinimumSize(new Dimension(161, 226));
          ??? this.setMaximumSize(getMinimumSize());
          ??? this.setPreferredSize(getMinimumSize());
          ??? this.setBorder(new BorderUIResource.EtchedBorderUIResource());
          ??? */
          ?? this.setSize(new Dimension(161, 226));
          ??? backButton.setFont(smallFont);
          ??? backButton.setLabel("<");
          ? //? backButton.setSize(insets);
          ?//?? backButton.setDefaultCapable(false);
          ??? backButton.addActionListener(new ActionListener() {
          ????? public void actionPerformed(final ActionEvent evt) {
          ??????? onBackClicked(evt);
          ????? }
          ??? });
          ??? add(backButton, new AbsoluteConstraints(10, 10, 20, 20));
          ??? monthAndYear.setFont(largeFont);
          ??? monthAndYear.setAlignment((int)TextField.CENTER_ALIGNMENT);
          ??? monthAndYear.setText(formatDateText(selectedDate.getTime()));
          ??? add(monthAndYear, new AbsoluteConstraints(30, 10, 100, 20));
          ??? forwardButton.setFont(smallFont);
          ??? forwardButton.setLabel(">");
          ?//?? forwardButton.setMargin(insets);
          //??? forwardButton.setDefaultCapable(false);
          ??? forwardButton.addActionListener(new ActionListener() {
          ????? public void actionPerformed(final ActionEvent evt) {
          ??????? onForwardClicked(evt);
          ????? }
          ??? });
          ??? add(forwardButton, new AbsoluteConstraints(130, 10, 20, 20));
          ??? int x = startX;
          ??? for (int ii = 0; ii < dayHeadings.length; ii++) {
          ??? //? dayHeadings[ii].setOpaque(true);
          ????? dayHeadings[ii].setBackground(Color.LIGHT_GRAY);
          ????? dayHeadings[ii].setForeground(Color.WHITE);
          ????? dayHeadings[ii].setAlignment((int)TextField.CENTER_ALIGNMENT);
          ??? //? dayHeadings[ii].setHorizontalAlignment(Label.CENTER);
          ????? add(dayHeadings[ii], new AbsoluteConstraints(x, 40, 21, 21));
          ????? x += 20;
          ??? }
          ??? x = startX;
          ??? int y = startY;
          ??? for (int ii = 0; ii < daysInMonth.length; ii++) {
          ????? for (int jj = 0; jj < daysInMonth[ii].length; jj++) {
          ????? //? daysInMonth[ii][jj].setOpaque(true);
          ??????? daysInMonth[ii][jj].setBackground(white);
          ??????? daysInMonth[ii][jj].setFont(smallFont);
          ???? //?? daysInMonth[ii][jj].setHorizontalAlignment(Label.CENTER);
          ??????? daysInMonth[ii][jj].setText("");
          ??????? daysInMonth[ii][jj].addMouseListener(new MouseAdapter() {
          ????????? public void mouseClicked(final MouseEvent evt) {
          ??????????? onDayClicked(evt);
          ????????? }
          ??????? });
          ??????? add(daysInMonth[ii][jj], new AbsoluteConstraints(x, y, 21, 21));
          ??????? x += 20;
          ????? }
          ????? x = startX;
          ????? y += 20;
          ??? }
          ??? initButtons(true);
          ??? calculateCalendar();
          ? }

          ? private void initButtons(final boolean firstTime) {
          ??? if (firstTime) {
          ????? final Dimension buttonSize = new Dimension(68, 24);
          ????? todayButton.setLabel("今天");
          ????? todayButton.setSize(buttonSize);
          ????? /*
          ????? todayButton.setMargin(insets);
          ????? todayButton.setMaximumSize(buttonSize);
          ????? todayButton.setMinimumSize(buttonSize);
          ????? todayButton.setPreferredSize(buttonSize);
          ????? todayButton.setDefaultCapable(true);
          ????? todayButton.setSelected(true);
          ????? */
          ????? todayButton.addActionListener(new ActionListener() {
          ??????? public void actionPerformed(final ActionEvent evt) {
          ????????? onToday(evt);
          ??????? }
          ????? });
          ????? cancelButton.setLabel("取消");
          ????? cancelButton.setSize(buttonSize);
          ????? /*
          ????? cancelButton.setMargin(insets);
          ????? cancelButton.setMaximumSize(buttonSize);
          ????? cancelButton.setMinimumSize(buttonSize);
          ????? cancelButton.setPreferredSize(buttonSize);
          ????? */
          ????? cancelButton.addActionListener(new ActionListener() {
          ??????? public void actionPerformed(final ActionEvent evt) {
          ????????? onCancel(evt);
          ??????? }
          ????? });
          ??? }
          ??? else {
          ????? this.remove(todayButton);
          ????? this.remove(cancelButton);
          ??? }
          ??? if (hideOnSelect) {
          ????? add(todayButton, new AbsoluteConstraints(25, 190, 52, -1));
          ????? add(cancelButton, new AbsoluteConstraints(87, 190, 52, -1));
          ??? }
          ??? else {
          ????? add(todayButton, new AbsoluteConstraints(55, 190, 52, -1));
          ??? }
          ? }

          ? private void onToday(final java.awt.event.ActionEvent evt) {
          ??? selectedDate = getToday();
          ??? setVisible(!hideOnSelect);
          ??? if (isVisible()) {
          ????? monthAndYear.setText(formatDateText(selectedDate.getTime()));
          ????? calculateCalendar();
          ??? }
          ? }

          ? private void onCancel(final ActionEvent evt) {
          ??? selectedDate = originalDate;
          ??? setVisible(!hideOnSelect);
          ? }

          ? private void onForwardClicked(final java.awt.event.ActionEvent evt) {
          ??? final int day = selectedDate.get(Calendar.DATE);
          ??? selectedDate.set(Calendar.DATE, 1);
          ??? selectedDate.add(Calendar.MONTH, 1);
          ??? selectedDate.set(Calendar.DATE,
          ???????????????????? Math.min(day, calculateDaysInMonth(selectedDate)));
          ??? monthAndYear.setText(formatDateText(selectedDate.getTime()));
          ??? calculateCalendar();
          ? }

          ? private void onBackClicked(final java.awt.event.ActionEvent evt) {
          ??? final int day = selectedDate.get(Calendar.DATE);
          ??? selectedDate.set(Calendar.DATE, 1);
          ??? selectedDate.add(Calendar.MONTH, -1);
          ??? selectedDate.set(Calendar.DATE,
          ???????????????????? Math.min(day, calculateDaysInMonth(selectedDate)));
          ??? monthAndYear.setText(formatDateText(selectedDate.getTime()));
          ??? calculateCalendar();
          ? }

          ? private void onDayClicked(final java.awt.event.MouseEvent evt) {
          ??? final Label fld = (Label) evt.getSource();
          ??? if (!"".equals(fld.getText())) {
          ????? fld.setBackground(highlight);
          ????? selectedDay = fld;
          ????? selectedDate.set(Calendar.DATE, Integer.parseInt(fld.getText()));
          ????? setVisible(!hideOnSelect);
          ??? }
          ? }

          ? private static GregorianCalendar getToday() {
          ??? final GregorianCalendar gc = new GregorianCalendar();
          ??? gc.set(Calendar.HOUR_OF_DAY, 0);
          ??? gc.set(Calendar.MINUTE, 0);
          ??? gc.set(Calendar.SECOND, 0);
          ??? gc.set(Calendar.MILLISECOND, 0);
          ??? return gc;
          ? }

          ? private void calculateCalendar() {
          ??? if (null != selectedDay) {
          ????? selectedDay.setBackground(white);
          ????? selectedDay = null;
          ??? }
          ??? final GregorianCalendar c = new GregorianCalendar(selectedDate.get(Calendar.
          ??????? YEAR), selectedDate.get(Calendar.MONTH), 1);
          ??? final int maxDay = calculateDaysInMonth(c);
          ??? final int selectedDay = Math.min(maxDay, selectedDate.get(Calendar.DATE));
          ??? int dow = c.get(Calendar.DAY_OF_WEEK);
          ??? for (int dd = 0; dd < dow; dd++) {
          ????? daysInMonth[0][dd].setText("");
          ??? }
          ??? int week;
          ??? do {
          ????? week = c.get(Calendar.WEEK_OF_MONTH);
          ????? dow = c.get(Calendar.DAY_OF_WEEK);
          ????? final Label fld = this.daysInMonth[week - 1][dow - 1];
          ????? fld.setText(Integer.toString(c.get(Calendar.DATE)));
          ????? if (selectedDay == c.get(Calendar.DATE)) {
          ??????? fld.setBackground(highlight);
          ??????? this.selectedDay = fld;
          ????? }
          ????? if (c.get(Calendar.DATE) >= maxDay)
          ??????? break;
          ????? c.add(Calendar.DATE, 1);
          ??? }
          ??? while (c.get(Calendar.DATE) <= maxDay); week--;
          ??? for (int ww = week; ww < daysInMonth.length; ww++) {
          ????? for (int dd = dow; dd < daysInMonth[ww].length; dd++) {
          ??????? daysInMonth[ww][dd].setText("");
          ????? }
          ????? dow = 0;
          ??? }
          ??? c.set(Calendar.DATE, selectedDay);
          ??? selectedDate = c;
          ? }

          ? private static int calculateDaysInMonth(final Calendar c) {
          ??? int daysInMonth = 0;
          ??? switch (c.get(Calendar.MONTH)) {
          ????? case 0:
          ????? case 2:
          ????? case 4:
          ????? case 6:
          ????? case 7:
          ????? case 9:
          ????? case 11:
          ??????? daysInMonth = 31;
          ??????? break;
          ????? case 3:
          ????? case 5:
          ????? case 8:
          ????? case 10:
          ??????? daysInMonth = 30;
          ??????? break;
          ????? case 1:
          ??????? final int year = c.get(Calendar.YEAR);
          ??????? daysInMonth = (0 == year % 1000) ? 29 : (0 == year % 100) ? 28 :
          ??????????? (0 == year % 4) ? 29 : 28;
          ??????? break;
          ??? }
          ??? return daysInMonth;
          ? }

          ? private static String formatDateText(final Date dt) {
          ??? final DateFormat df = DateFormat.getDateInstance(DateFormat.LONG);
          ??? final StringBuffer mm = new StringBuffer();
          ??? final StringBuffer yy = new StringBuffer();
          ??? final FieldPosition mmfp = new FieldPosition(DateFormat.MONTH_FIELD);
          ??? final FieldPosition yyfp = new FieldPosition(DateFormat.YEAR_FIELD);
          ??? df.format(dt, mm, mmfp);
          ??? df.format(dt, yy, yyfp);
          ??? return (mm.toString().substring(mmfp.getBeginIndex(), mmfp.getEndIndex()) +
          ??????????? "月 " +
          ??????????? yy.toString().substring(yyfp.getBeginIndex(), yyfp.getEndIndex()) +
          ??????????? "年");
          ? }
          }

          posted @ 2006-04-27 14:32 Kun Tao's Blog 閱讀(272) | 評論 (0)編輯 收藏

          2005年10月25日 #

          從前,有一座圓音寺,每天都有許多人上香拜佛,香火很旺。在圓音寺廟前的橫梁上有個蜘蛛結了張網,由于每天都受到香火和虔誠的祭拜的熏托,蛛蛛便有了佛性。經過了一千多年的修煉,蛛蛛佛性增加了不少。   忽然有一天,佛主光臨了圓音寺,看見這里香火甚旺,十分高興。離開寺廟的時候,不輕易間地抬頭,看見了橫梁上的蛛蛛。佛主停下來,問這只蜘蛛:“你我相見總算是有緣,我來問你個問題,看你修煉了這一千多年來,有什么真知拙見。怎么樣?”蜘蛛遇見佛主很是高興,連忙答應了。佛主問到:“世間什么才是最珍貴的?”蜘蛛想了想,回答到:“世間最珍貴的是‘得不到’和‘已失去’?!狈鹬鼽c了點頭,離開了。   就這樣又過了一千年的光景,蜘蛛依舊在圓音寺的橫梁上修煉,它的佛性大增。一日,佛主又來到寺前,對蜘蛛說道:“你可還好,一千年前的那個問題,你可有什么更深的認識嗎?”蜘蛛說:“我覺得世間最珍貴的是‘得不到’和‘已失去’?!狈鹬髡f:“你再好好想想,我會再來找你的?!?  又過了一千年,有一天,刮起了大風,風將一滴甘露吹到了蜘蛛網上。蜘蛛望著甘露,見它晶瑩透亮,很漂亮,頓生喜愛之意。蜘蛛每天看著甘露很開心,它覺得這是三千年來最開心的幾天。突然, 又刮起了一陣大風,將甘露吹走了。蜘蛛一下子覺得失去了什么,感到很寂寞和難過。這時佛主又來了,問蜘蛛:“蜘蛛這一千年,你可好好想過這個問題:世間什么才是最珍貴的?”蜘蛛想到了甘露,對佛主說:“世間最珍貴的是‘得不到 ’和‘已失去’?!狈鹬髡f:“好,既然你有這樣的認識,我讓你到人間走一朝吧?!?  就這樣,蜘蛛投胎到了一個官宦家庭,成了一個富家小姐,父母為她取了個名字叫蛛兒。一晃,蛛兒到了十六歲了,已經成了個婀娜多姿的少女,長的十分漂亮,楚楚動人。   這一日,新科狀元郎甘鹿中士,皇帝決定在后花園為他舉行慶功宴席。來了許多妙齡少女,包括蛛兒,還有皇帝的小公主長風公主。狀元郎在席間表演詩詞歌賦,大獻才藝,在場的少女無一不被他折倒。但蛛兒一點也不緊張和吃醋,因為她知道,這是佛主賜予她的姻緣。   過了些日子,說來很巧,蛛兒陪同母親上香拜佛的時候,正好甘鹿也陪同母親而來。上完香拜過佛,二位長者在一邊說上了話。蛛兒和甘鹿便來到走廊上聊天,蛛兒很開心,終于可以和喜歡的人在一起了,但是甘鹿并沒有表現出對她的喜愛。蛛兒對甘鹿說:“你難道不曾記得十六年前,圓音寺的蜘蛛網上的事情了嗎?”甘鹿很詫異,說:“蛛兒姑娘,你漂亮,也很討人喜歡,但你想象力未免豐富了一點吧。”說罷,和母親離開了。   蛛兒回到家,心想,佛主既然安排了這場姻緣,為何不讓他記得那件事,甘鹿為何對我沒有一點的感覺?   幾天后,皇帝下召,命新科狀元甘鹿和長風公主完婚;蛛兒和太子芝草完婚。這一消息對蛛兒如同晴空霹靂,她怎么也想不同,佛主竟然這樣對她。幾日來,她不吃不喝,窮究急思,靈魂就將出殼,生命危在旦夕。太子芝草知道了,急忙趕來,撲倒在床邊,對奄奄一息的蛛兒說道:“那日,在后花園眾姑娘中,我對你一見鐘情,我苦求父皇,他才答應。如果你死了,那么我也就不活了?!闭f著就拿起了寶劍準備自刎。   就在這時,佛主來了,他對快要出殼的蛛兒靈魂說:“蜘蛛,你可曾想過,甘露(甘鹿)是由誰帶到你這里來的呢?是風(長風公主)帶來的,最后也是風將它帶走的。甘鹿是屬于長風公主的,他對你不過是生命中的一段插曲。而太子芝草是當年圓音寺門前的一棵小草,他看了你三千年,愛慕了你三千年,但你卻從沒有低下頭看過它。蜘蛛,我再來問你,世間什么才是最珍貴的?”蜘蛛聽了這些真相之后,好象一下子大徹大悟了,她對佛主說:“世間最珍貴的不是‘得不到’和‘已失去’,而是現在能把握的幸福?!眲傉f完,佛主就離開了,蛛兒的靈魂也回位了,睜開眼睛,看到正要自刎的太子芝草,她馬上打落寶劍,和太子深深的抱著……   故事結束了,你能領會蛛兒最后一刻的所說的話嗎?“世間最珍貴的不是‘得不到’ 和‘已失去’,而是現在能把握的幸福?!?
          posted @ 2005-10-25 20:14 Kun Tao's Blog 閱讀(234) | 評論 (0)編輯 收藏

          2005年10月21日 #

               摘要: 2.1.3. 優(yōu)缺點 優(yōu)點: 一些開發(fā)商開始采用并推廣這個框架作為開源項目,有很多先進的實現思想對大型的應用支持的較好有集中的網頁導航定義 缺點: 不是業(yè)屆標準對開發(fā)工具的支持不夠復雜的taglib,需要比較長的時間來掌握html form 和 actionform的搭配比較封閉,但這也是它的精華所在。 修改建議把actionform屬性的設置器和訪問器修改成讀取或生成xml文檔的方法,然后 ht...  閱讀全文
          posted @ 2005-10-21 20:38 Kun Tao's Blog 閱讀(295) | 評論 (0)編輯 收藏

               摘要: 轉載說明:本文主要講述內容:J2EE web架構基線,模型選取以及幾個模型的優(yōu)缺點對比。一、J2EE體系包括java server pages(JSP) ,java SERVLET, enterprise bean,WEB service等技術。怎樣把這些技術組合起來形成一個適應項目需要的穩(wěn)定架構是項目開發(fā)過程中一個非常重要的步驟。完成這個步驟可以形成一個主要里程碑基線。1.各種因數初步確定 為了...  閱讀全文
          posted @ 2005-10-21 20:21 Kun Tao's Blog 閱讀(265) | 評論 (0)編輯 收藏

               摘要: 注:目前J2EE的開發(fā)工作網絡上討論的熱火朝天,各種新技術層出不窮,當然了我們這些新手看的也是一頭霧水,感覺的j2ee涉及到的技術太廣,各種framework令人眼花繚亂,今天看了這篇介紹性文章,感覺不錯,和大家分享一下文章的主要觀點。(其中提到的一些技術或規(guī)范可能比較老了,主要是學習一下作者的觀點) 1.結合商業(yè)需求選擇合理的架構一般而言,企業(yè)信息系統(EIS)都要求自己穩(wěn)定、安全、可靠、高效、...  閱讀全文
          posted @ 2005-10-21 19:43 Kun Tao's Blog 閱讀(249) | 評論 (0)編輯 收藏

          2005年9月21日 #

          建立,打包,部署及運行Duke 銀行應用程序 
          作者:Jimsons
          目錄
          From:http://www.21tx.com/dev/2005/04/23/33123.html
          1. 準備工作...
          2.    啟動服務器...
          2.1創(chuàng)建銀行數據庫...
          2.2捕獲數據庫模式...
          2.3創(chuàng)建JDBC數據源...
          2.4 將用戶和組添加到file域...
          3. 編譯Duke銀行應用程序代碼...
          4. 打包并部署Duke銀行應用程序...
          4.1 打包企業(yè)Beans.
          4.2 打包應用程序客戶端...
          4.3 打包Web客戶端...
          4.4 打包并部署應用程序...
          5. 運行應用程序客戶端Application Client
          6. 運行Web客戶端...
          7. 關于例子源代碼中的錯誤更正...
          7.1 NextIdBean代碼中的錯誤...
          7.2 Web模塊中的錯誤...
          8. 參考資料...  
           
          1. 準備工作
          假設你的計算機中已經安裝了J2EE 1.4 SDK,在建立DUKE銀行應用程序之前,你必須到http://java.sun.com/j2ee/1.4/download.html #tutorial下載j2eetutorial壓縮包并將其解壓縮,假定你解壓的路徑為<INSTALL>/j2eetutorial14,打開例子的配置文件<INSTALL>/j2eetutorial14/examples/common/build.properties
          l         將j2ee.home的值設為你應用程序服務器(Application Server)的安裝位置,例如你的應用程序服務器安裝在C:/Sun/AppServer,那么你應該設置如下: j2ee.home=C:/Sun/AppServer
          l         將j2ee.tutorial.home  的值設置為你j2eetutorial的安裝位置,例如: j2ee.tutorial.home=C:/j2eetutorial14
          l         假如你安裝應用程序服務器的時候管理員的用戶名不是用默認的admin,那你要將admin.user的值改為你設置的用戶名
          l         假如你安裝應用程序服務器時不是用默認的8080端口,則要將domain.resources.port的值改為你設置的端口.
          l         將<INSTALL>/j2eetutorial14/examples/common/admin-password.txt文件中AS_ADMIN_PASSWORD的值設為你安裝應用程序服務器時設置的管理員密碼,如: AS_ADMIN_PASSWORD=yourpassword
          2.      啟動服務器
          你必須先啟動PointBase數據庫服務器并且向數據庫中添加客戶和帳號的資料,你還要向應用程序服務器中添加一些資源, 最后你才能開始打包,部署和運行例子.
          2.1創(chuàng)建銀行數據庫
          你必須先創(chuàng)建數據庫并向數據表中輸入數據,然后企業(yè)Bean才能從中讀取或向其中寫入數據,請根據以下步驟來創(chuàng)建數據表并輸入數據:
          1.       啟動PointBase數據庫服務器
          2.       打開命令行,轉到<INSTALL>/j2eetutorial14/examples/bank/目錄下,執(zhí)行命令asant create-db_common, 這條命令調用PointBase終端工具庫執(zhí)行<INSTALL>/j2eetutorial14/examples/bank/sql/create-table.sql中的SQL語句, 這些SQL語句的功能是先刪除所有已經存在的表并創(chuàng)建新表并向表中插入數據, 因為第一次運行這些語句時這些表并不存在, 所以你會看到一些SQL錯誤信息,你可以忽略不理這些錯誤信息.
          2.2捕獲數據庫模式
          在創(chuàng)建表并輸入數據之后,你可以捕獲表間的結構并保存到一個模式文件中,請通過以下步驟來捕獲模式:
          1.       打開命令行并切換到<INSTALL>/j2eetutorial14/examples/bank/目錄
          2.       執(zhí)行以下命令asant capture-db-schema , 執(zhí)行此命令后生成模式文件<INSTALL>/j2eetutorial14/examples/bank/build/dukesbank.dbschema
          2.3創(chuàng)建JDBC數據源
          Duke銀行的企業(yè)Bean用JNDI名jdbc/BankDB來引用數據庫,請執(zhí)行以下步驟:
          1.       打開管理終端頁面http://localhost:4848/asadmin
          2.       展開JDBC分支,選擇JDBC Resources, 選擇 New
          3.       將其命名為jdbc/BankDB并將它映射到 PointBasePool
          2.4 將用戶和組添加到file域
          將用戶和組添加到file安全域后,應用程序服務器就能判斷哪些用戶能訪問Web客戶端的企業(yè)Bean的方法和資源,添加的步驟如下:
          1.       打開管理終端頁面http://localhost:4848/asadmin
          2.       展開Configuration分支并展開Security分支
          3.       展開Realms分支并選中file域
          4.       點擊Manage Users并點擊New
          5.       根據下表輸入Duke銀行的用戶和組
          User
          Password
          Group
          200
          j2ee
          bankCustomer
          bankadmin
          j2ee
          bankAdmin
           
          3. 編譯Duke銀行應用程序代碼
          打開命令行,轉到<INSTALL>/j2eetutorial14/examples/bank/目錄,執(zhí)行命令asant build ,這個命令就編譯了企業(yè)Bean,應用程序客戶端和Web客戶端的全部代碼,編譯后的代碼位于<INSTALL>/j2eetutorial14/examples/bank/build目錄下.
          4. 打包并部署Duke銀行應用程序
          以下過程假設你對用部署工具打包企業(yè)Bean, 應用程序客戶端和Web應用程序的過程都比較熟悉,下面介紹如何打包并部署Duke銀行(如果你按照以下步驟做了之后,部署或運行此應用程序還存在問題,那你可以用我們在<INSTALL>/j2eetutorial14/examples/bank/provided-jars/ 目錄下提供的EAR文件即打包好的文件來部署和運行這個例子)
          4.1 打包企業(yè)Beans
          1.       創(chuàng)建一個EJB JAR模塊并命名為DukesBankEJBJAR ,將其保存到<INSTALL>/j2eetutorial14/examples/bank/目錄下.
          2.       添加<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/目錄下的ejb和util包, 還有 <INSTALL>/j2eetutorial14/examples/bank/build/目錄下的dukesbank.dbschema文件.
          3.       創(chuàng)建實體Beans(選擇添加到DukesBankEJBJAR中)
          a. 用企業(yè)Bean向導創(chuàng)建下面每個表格中的CMP2.0 (容器管理持久性) 企業(yè)bean:
           
          AccountBean的設置如下表:
          Setting
          Value
          Local Home Interface
          LocalAccountHome
          Local Interface
          LocalAccount
          Persistent Fields
          accountId, balance, beginBalance, beginBalanceTimeStamp, creditLine, description, type
          Abstract Schema Name
          AccountBean
          Primary Key Class
          Existing field accountId
          CustomerBean的設置如下表:
           
          Setting
          Value
          Local Home Interface
          LocalCustomerHome
          Local Interface
          LocalCustomer
          Persistent Fields
          city, customerId, email, firstName, lastName, middleInitial, phone, state, street, zip
          Abstract Schema Name
          CustomerBean
          Primary Key Class
          Existing field customerId
          TxBean的設置如下表:
           
          Setting
          Value
          Local Home Interface
          LocalTxHome
          Local Interface
          LocalTx
          Persistent Fields
          amount, balance, description, timeStamp, txId
          Abstract Schema Name
          TxBean
          Primary Key Class
          Existing field txId
          NextIdBean的設置如下表:
           
          Setting
          Value
          Local Home Interface
          LocalNextIdHome
          Local Interface
          LocalNextId
          Persistent Fields
          beanName, id
          Abstract Schema Name
          NextIdBean
          Primary Key Class
          Existing field beanName
           
          4. 根據下表建立實體bean的關系:
           
          Multi-plicity
          Bean A
          Field Referencing Bean B and Field Type
          Bean B
          Field Referencing Bean A and Field Type
          *:*
          AccountBean
          customers, java.util.Collection
          CustomerBean
          accounts, java.util.
          Collection
          1:*
          AccountBean
          none
          TxBean
          account
           
          b. 在Sun-specific SettingsàCMP Database 對話框
          1.       將JNDI名字命名為jdbc/BankDB
          2.       點擊Create Database Mappings,選中Map to Tables in Database Schema File并從下拉列表中選擇dukesbank.dbschema,如下圖所示
          3.       每選擇一個企業(yè)bean,下方就會顯示持久域的映射, 請確認那些域和關系.
          c. 根據下表為finder設置EJB QL查詢語句
           
          Duke銀行中的finder查詢
          Enterprise Bean
          Method
          EJB QL Query
          AccountBean
          findByCustomerId
          select distinct object(a)
          from AccountBean a, in (a.customers) as c
          where c.customerId = ?1
          CustomerBean
          findByAccountId
          select distinct object(c)
          from CustomerBean c, in (c.accounts) as a
          where a.accountId = ?1
          CustomerBean
          findByLastName
          select object(c)
          from CustomerBean c
          where c.lastName = ?1
          TxBean
          findByAccountId
          select object(t)
          from TxBean t
          where t.account.accountId = ?3
          and (t.timeStamp >= ?1 and t.timeStamp <= ?2)
          d. 在NextIdBean的Transaction標簽中,將 NextIdBean.getNextId 方法的Transaction Attributes屬性設置為Requires New.
           
          5. 調用企業(yè)Bean向導創(chuàng)建下表中的stateful session beans(即有狀態(tài)會話bean)
           
          Session Bean
          Home Interface
          Remote Interface
          Implementation Class
          Account
          ControllerBean
          Account
          ControllerHome
          Account
          Controller
          AccountControllerBean
          Customer
          ControllerBean
          Customer
          ControllerHome
          Customer
          Controller
          CustomerControllerBean
          TxControllerBean
          TxControllerHome
          TxController
          TxBean
              
          a.       根據下表列出的添加session beans 到local entity beans 的EJB references即EJB引用.
           
          EJB References in AccountControllerBean
          Coded Name
          EJB Type
          Interfaces
          Home Interface
          Local Interface
          Enterprise Bean Name
          ejb/account
          Entity
          Local
          Local
          AccountHome
          LocalAccount
          AccountBean
          ejb/
          customer
          Entity
          Local
          Local
          CustomerHome
          LocalCustomer
          CustomerBean
          ejb/nextId
          Entity
          Local
          Local
          NextIdHome
          LocalNextId
          NextIdBean
          EJB References in CustomerControllerBean
          Coded Name
          EJB Type
          Interfaces
          Home Interface
          Local Interface
          Enterprise Bean Name
          ejb/customer
          Entity
          Local
          Local CustomerHome
          Local
          Customer
          CustomerBean
          ejb/nextId
          Entity
          Local
          Local
          NextIdHome
          Local
          NextId
          NextIdBean
          EJB References in TxControllerBean
          Coded Name
          EJB Type
          Interfaces
          Home Interface
          Local Interface
          Enterprise Bean Name
          ejb/account
          Entity
          Local
          Local
          AccountHome
          Local
          Account
          AccountBean
          ejb/
          tx
          Entity
          Local
          Local
          TxHome
          LocalTx
          TxBean
          ejb/nextId
          Entity
          Local
          Local
          NextIdHome
          Local
          NextId
          NextIdBean
           
          b.       將所有session bean的Transaction Management設置為Container-Managed即容器管理
          6.       保存這個模塊
           
          4.2 打包應用程序客戶端
                 1. 調用 Application Client 向導
          a.      創(chuàng)建一個應用程序客戶端模塊,將它命名為DukesBankACJAR并把它保存到<INSTALL>/j2eetutorial14/examples/bank/目錄下
          b.      添加<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/目錄下的appclient, util, ejb/exception包和 ejb/*/*Controller* 即home和遠程接口文件(即AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TxController, TxControllerHome) 到JAR中.
          c.       選擇appclient.BankAdmin 作為應用程序客戶端的main class (主類)
          2. 根據下表添加對session bean的EJB 引用
          Coded Name
          EJB Type
          Interface
          JNDI Name of Session Bean
          ejb/accountController
          Session
          Remote
          AccountControllerBean
          ejb/customerController
          Session
          Remote
          CustomerControllerBean
          3. 保存這個模塊.
          4.3 打包Web客戶端
          1.      通過Web Component向導創(chuàng)建一個web模塊,命名為DukesBankWAR并保存到<INSTALL>/j2eetutorial14/examples/bank/目錄下,選擇Dispatcher 作為Servlet類,其它保持默認.
          2.      添加以下內容到web模塊中
          a.      添加<INSTALL>/j2eetutorial14/examples/bank/build/com/sun/ebank/目錄下的web, util, ejb/exception包和 ejb/*/*Controller* 即home和遠程接口文件(即AccountController, AccountControllerHome, CustomerController, CustomerControllerHome, TxController, TxControllerHome) 到模塊中.
          b.      添加<INSTALL>/j2eetutorial14/examples/bank/build/目錄下的template目錄,所有的jsp頁面,所有的WebMessages*.properties文件和tutorial-template.tld文件到模塊中.
          c.       在添加文件的對話框中將WebMessages*.properties文件從根目錄拖到WEB-INF/classes目錄下,如下圖
           
          3.      將context root 設置為 /bank
          4.      打開Dispatcher組件的Aliases標簽, 添加/accountHist, /accountList, /atm, /atmAck, /main, /transferAck, /transferFunds, and /logoff作為aliases
          5.      添加下表列出的session bean對EJB 的引用
          Coded Name
          EJB Type
          Interface
          JNDI Name of Session Bean
          ejb/accountController
          Session
          Remote
          AccountControllerBean
          ejb/customerController
          Session
          Remote
          CustomerControllerBean
          ejb/txController
          Session
          Remote
          TxControllerBean
          6.      在標簽JSP property添加名為bank的組,這個組對應的URL pattern(URL模式)為*.jsp,添加/template/prelude.jspf 到include prelude 中
          7.      在Context標簽,添加參數名為javax.servlet.jsp.jstl.fmt.localizationContext,值為WebMessages.
          8.      在Security標簽添加安全控制
          a. 選擇Form Based作為user authentication方法,在authentication設置中將realm的值設置為file, login page (登錄頁) 設置為/logon.jsp, error page (錯誤頁)設置為/logonError.jsp.
          b. 添加一個security constraint和web resource collection, 用deploytool提供的默認名稱
          c. 在web resource collection.中添加URL Patterns(URL模式): /main, /accountList, /accountHist, /atm, /atmAck, /transferFunds, 和 /transferAck
          d. 選中HTTP方法POST和GET.
          e. 添加安全角色(authorized role ) bankCustomer
                 9. 保存這個模塊
           
          4.4 打包并部署應用程序
          1.      創(chuàng)建一個J2EE application(J2EE應用程序), 將它命名為DukesBankApp,并保存到<INSTALL>/j2eetutorial14/examples/bank/目錄下
          2.     添加DukesBankACJAR應用程序客戶端模塊到DukesBankApp
          3.     添加DukesBankEJBJAR即EJB模塊到DukesBankApp
          4.     添加DukesBankWAR即Web模塊到DukesBankApp
          5.     添加安全角色(security roles) 名為 bankAdminbankCustomer
          6.     為企業(yè)bean添加以下的安全設置(security settings)
          a.     AccountControllerBean:在Security標簽,將方法removeCustomerFromAccount, removeAccount, createAccount, 和 addCustomerToAccount的限制訪問權限的安全角色為bankAdmin ;在General標簽, 點擊Sun-specific Settings,然后在彈出的對話框中點擊IOR, 在Context對話框將Required設置為true, 將realm設置為file.
          b.     CustomerControllerBean: 在Security標簽,將方法getCustomersOfAccount, createCustomer, getCustomersOfLastName, setName, removeCustomer, 和 setAddress的限制訪問權限的安全角色為bankAdmin ;在General標簽, 點擊Sun-specific Settings,然后在彈出的對話框中點擊IOR, 在Context對話框將Required設置為true, 將realm設置為file.
          c.     TxControllerBean:在Security標簽,將方法getTxsOfAccount, makeCharge, deposit, transferFunds, withdraw, 和 makePayment的限制訪問權限的安全角色為bankCustomer
          7.     如果你還沒有啟動應用程序服務器(Application Server.)那你現在就啟動它.
          8.     將bankCustomer角色映射到bankCustomer組
          9.     將bankAdmin角色映射到bankAdmin組
          10.  保存這個應用程序模塊
          11.  Deploy(部署)這個應用程序,在部署kesBankApp對話框選中Return Client Jar即返回客戶端Jar選項.
          12.  在deploytool中選中server,將右邊出現的bank選中并啟動它.
          5. 運行應用程序客戶端Application Client
          請根據以下步驟來運行應用程序客戶端:
          1.           打開命令行,轉到<INSTALL>/j2eetutorial14/examples/bank/目錄下
          2.           如果是要運行英文版本的客戶端就輸入以下命令:        appclient -client DukesBankAppClient.jar
          DukesBankAppClient.jar這個文件是你剛才部署時選中返回客戶端JAR而返回的文件.
          3.           如果想運行西班牙語版本的客戶端則運行以下命令:
          appclient -client DukesBankAppClient.jar es
          4.           在彈出的登錄框中,輸入用戶名bankadmin密碼為 j2ee,然后你就可以看到以下的界面.
           
          6. 運行Web客戶端
          請根據以下步驟來運行Web客戶端
          1.     請在瀏覽器中打開地址http://localhost:8080/bank/main ,如果查看西班牙版本的客戶端則只需在瀏覽器的語言設置中更改.
          2.     在登錄頁面,輸入用戶名200,密碼j2ee并提交.
          3.     當你選擇Account List,則你會看到以下畫面.
           
          7. 關于例子源代碼中的錯誤更正
                 7.1 NextIdBean代碼中的錯誤
              此錯誤會造成部署發(fā)生錯誤不能完成,將<INSTALL>/j2eetutorial14/examples/bank/src/com/sun/ebank/ejb/util/目錄下的NextIdBean.java文件打開,找到下面這行代碼
          public Object ejbCreate() throws CreateException {
          將方法ejbCreate()的返回類型由Object更改為String,再重新編譯,并在deploytool中更新此文件,重新部署即可成功
                 7.2 Web模塊中的錯誤
              打開Web客戶端,輸入用戶名密碼然后提交可能會拋出javax.servlet.jsp.JspTagException錯誤,請根據以下步驟進行更正:
                  1. 用文本編輯器新建java文檔命名為CustomerHackFilter,保存到<INSTALL>/j2eetutorial14/examples/bank/src/com/sun/ebank/web目錄下,內容如下:
          package com.sun.ebank.web;
           
          import javax.servlet.*;
          import javax.servlet.http.*;
          import com.sun.ebank.util.Debug;
          import com.sun.ebank.web.*;
          import java.io.IOException;
           
          /**
           * this is a dumb hack.  update 4 seems to broken unless a
           * CustomerBean is placed in the request linked to the BeanManager.
           * Naturally, we need to add a BeanManager to the session here,
           * doing some of the work the dispatcher should have done.
           */
          public class CustomerHackFilter  implements Filter
          {
              private FilterConfig filterConfig = null;
                  public void init(FilterConfig filterConfig)
                  throws ServletException
              {
                  this.filterConfig = filterConfig;
              }
           
              public void destroy() {
                  this.filterConfig = null;
              }
           
              public void doFilter(ServletRequest req, ServletResponse response,
                                   FilterChain chain)
                  throws IOException,
                         ServletException
              {
                  HttpServletRequest request = (HttpServletRequest) req;
                  HttpSession        session = request.getSession();
           
                  BeanManager beanManager =
                      (BeanManager) session.getAttribute("beanManager");
           
                  if (beanManager == null) {
                      Debug.print("hack - Creating bean manager.");
                      beanManager = new BeanManager();
                      session.setAttribute("beanManager", beanManager);
                  }
           
                  CustomerBean customerBean = new CustomerBean();
                  customerBean.setBeanManager(beanManager);
                  request.setAttribute("customerBean", customerBean);
                  Debug.print("hack - added customerBean to request");
           
                  chain.doFilter(request, response);
              }
          }
             2. 重新編譯源代碼
             3. 選中DukesBankWAR模塊,編輯內容,找到com/sun/ebank/web/ CustomerHackFilter.class,將它添加到包中.
             4. 選中DukesBankWAR模塊,在Filter Mapping標簽,點擊Edit Filter List,在彈出的對話框中點擊Add Filter,在Filter Class下拉列表中選中com.sun.ebank.web.CustomerHackFilter,Filter Name為CustomerHack,選擇OK
             5. 還是在這個標簽在,點擊Add,彈出 “Add Servlet Filter Mapping”,在Filter Name下拉列表中選CustomerHack,下面選中 “Filter this Servlet”,選OK,如下圖.
             6. 保存這個模塊并重新部署運行即可修正錯誤
          posted @ 2005-09-21 19:44 Kun Tao's Blog 閱讀(433) | 評論 (0)編輯 收藏

          2005年9月17日 #

          Duke執(zhí)行環(huán)境:
          1.J2SE JDK;(download from :http://java.sun.com/j2se/download.html#sdk)
          2.J2EE JDK;(download from :http://java.sun.com/j2ee/download.html#sdk)
          3.Ant;(download from:http://jakarta.apathe.org/builds/jakarta-ant)
          4.Structs;(download from:http://jakarta.apathe.org/builds/jakarta-structs)
          5.J2ee Tutorial;(download from :http://java.sun.com/j2ee/download.html#tutorial)
          環(huán)境配置:
          1.略
          2.J2EE運行環(huán)境的搭建

          開發(fā)企業(yè)級的應用程序需要搭建好J2EE的運行環(huán)境。其實也就是到SUN公司的網站上去DOWNJ2EE 1.4 SDK開發(fā)工具包。然后雙擊安裝文件,如果你下載的版本與我的一樣。那么這個安裝文件就會是這個名字:j2eesdk-1_4-dr-windows-eval.exe。同樣的我們也將J2EE SDK安裝在C盤根目錄下。

          需要特別提醒大家的是:J2EE運行環(huán)境的搭建是以J2SE運行環(huán)境的搭建為基礎的。其實想也想得到為什么。如果沒有JDK,哪里來的編譯和運行命令呢(JAVAjavac)。安裝完J2EE 1.4 SDK包后,具體的設置與測試步驟如下:

          1、  首先右往PATH變量里添加J2EE SDKBIN目錄。如:C:\j2sdkee1.3.1\bin。如何往里面添加,前面已經講過。

          2、  然后新建兩個變量:一個是JAVA_HOME,變量值為:JDK的安裝目錄。另一個是J2EE_HOME,變量值為J2EE SDK的安裝目錄。如圖示:
          3、  最后往CLASSPATH變量里添加一個關鍵的JAR包。它就是J2EE.JAR包。比如我添加的就是:C:\j2sdkee1.3.1\lib\j2ee.jar。

          4、  所有的工作做完以后。大家可以通過以下方式驗證一下我們的J2EE環(huán)境是否已經搭建成功。在命令提示符狀態(tài)下輸入命令:J2EE Verbose。如果屏幕的最下面看到了這樣一句話J2EE server startup complete.那就表示J2EE服務器成功啟動了。在我們的J2EE程序要布署和運行的過程中。服務器將一直啟動著。

          另外提一下,如果你需要停止J2EE服務器,必須再開一個命令窗口,并運行如下命令:J2EE –STOP。成功運行后,將會有提示語句。再去看看啟動服務器的那個窗口,你將可以看到提示符了。

          5、  這樣做了還不夠,我們還需要到網頁里去測試一下服務器默認頁面是否能夠正常顯示,這樣才能保證我們能夠進WEB程序的開發(fā)。雙擊IE瀏覽器的圖標,在地址欄里輸入:http://localhost:8000,如果你能看到以下窗口中的內容,那就說明你的J2EE環(huán)境已經搭建成功。需要說明一點,在localhost:后的是J2EE服務器提供的WEB服務端口號。

          需要提醒大家的是:當你打開網頁之前,確認你的J2EE服務器是啟動著的。如果你機器上沒有安裝網卡,或是網卡安裝不正確,也會導致無法打開J2EE服務器默認頁面。

           

          posted @ 2005-09-17 20:47 Kun Tao's Blog 閱讀(650) | 評論 (0)編輯 收藏

          2005年7月19日 #

          常用的ant的操作

          常用的ant的操作,方便自己查詢,所以傳到網上,如果有朋友覺得不夠,請補充:
          主要的內容有

            (1)建立一個項目
            (2)建立屬性
            (3)對數據庫的操作
            (4)javac編譯
            (5)刪除目錄
            (6)建立目錄
            (7)拷貝文件群
            (8)jar為一個包
            (9)拷貝單個文件
            (10)運行
          有更多更好的常用的,我沒想到的,希望大家補充。  
            
          <!--(1)建立一個項目,默認的操作為target=all. -->
          <project name="proj" default="all" basedir=".">

            <!--(2)建立一些屬性,以供下邊的操作用到 -->
            <property name="root"  value="./" />
            <property name="deploy_path"  value="d:/deploy" />
            <property name="srcfile"  value="d:/srcfile" /> 
           
            <target name="all" depends="compile,deploy"/>
           
            <!--(3)對數據庫的操作 demo.ddl中寫的是sql語句 driver,url,userid,password隨具體情況設置--> 
            <!-- Oracle -->
            <target name="db_setup_oracle" description="Database setup for Oracle">
              <antcall target="check_params_results"/>
              <sql driver="oracle.jdbc.driver.OracleDriver"
                 url="jdbc:oracle:thin:@192.168.0.1:1521:oa"
                 userid="oa" password="oa"
                 onerror="continue"
                 print="yes"
                 src="./demo.ddl"/>
            </target>

            <!--(4)javac編譯 --> 
            <target name="compile">  
              <javac srcdir="${srcfile}"
                destdir="${root}/oa/"
                includes="*.java"
                classpath="${CLASSPATH};${CLIENT_CLASSES}/utils_common.jar"   <!--CLASSPATH和CLIENT_CLASSES是環(huán)境變量-->
              />
            </target>
           
            <target name="deploy" depends="compile">
              <!-- Create the time stamp -->
              <tstamp/>
             
              <!--(5)刪除目錄-->   
              <!--(6)建立目錄-->

              <delete dir="${root}/dist/"/>   
              <mkdir dir="${root}/dist/"/>      

              <delete dir="${deploy_path}"/>   
              <mkdir dir="${deploy_path}"/>    
           
              <!--(7)拷貝文件群-->
              <copy todir="${root}/dist/">    
                      <fileset dir="${root}/oa/">
                          <include name="*.class"/>
                      </fileset>
              </copy&g

          posted @ 2005-07-19 16:56 Kun Tao's Blog 閱讀(209) | 評論 (0)編輯 收藏

          2005年7月13日 #

          The Java interpreter proceeds as follows. First, it finds the environment variable CLASSPATH (set via the operating system, and sometimes by the installation program that installs Java or a Java-based tool on your machine). CLASSPATH contains one or more directories that are used as roots in a search for .class files. Starting at that root, the interpreter will take the package name and replace each dot with a slash to generate a path name from the CLASSPATH root (so package foo.bar.baz becomes foo\bar\baz or foo/bar/baz or possibly something else, depending on your operating system). This is then concatenated to the various entries in the CLASSPATH. That’s where it looks for the .class file with the name corresponding to the class you’re trying to create. (It also searches some standard directories relative to where the Java interpreter resides).
          posted @ 2005-07-13 15:08 Kun Tao's Blog 閱讀(290) | 評論 (0)編輯 收藏

          ps:from Thinking in Java chapter 4

          Consider a class called Dog:

          1. The first time an object of type Dog is created (the constructor is actually a static method), or the first time a static method or static field of class Dog is accessed, the Java interpreter must locate Dog.class, which it does by searching through the classpath. 
          2. As Dog.class is loaded (creating a Class object, which you’ll learn about later), all of its static initializers are run. Thus, static initialization takes place only once, as the Class object is loaded for the first time. 
          3. When you create a new Dog( ), the construction process for a Dog object first allocates enough storage for a Dog object on the heap. 
          4. This storage is wiped to zero, automatically setting all the primitives in that Dog object to their default values (zero for numbers and the equivalent for boolean and char) and the references to null
          5. Any initializations that occur at the point of field definition are executed. 
          6. Constructors are executed. As you shall see in Chapter 6, this might actually involve a fair amount of activity, especially when inheritance is involved.
          posted @ 2005-07-13 09:22 Kun Tao's Blog 閱讀(220) | 評論 (0)編輯 收藏

          僅列出標題  下一頁
          主站蜘蛛池模板: 大同县| 龙陵县| 庆阳市| 葵青区| 全州县| 田林县| 宁安市| 桃园县| 左贡县| 文成县| 惠州市| 桓仁| 铜鼓县| 武定县| 吴桥县| 海丰县| 天等县| 东阿县| 天峨县| 眉山市| 梅州市| 民权县| 常德市| 宁津县| 德保县| 南城县| 巴林左旗| 赤城县| 望谟县| 奉新县| 关岭| 县级市| 金溪县| 那曲县| 迁安市| 红安县| 夏河县| 睢宁县| 南雄市| 景宁| 扎赉特旗|