<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    FreeMan

    Java是條不歸路……

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      4 隨筆 :: 1 文章 :: 2 評論 :: 0 Trackbacks

    2007年10月30日 #

    1:創建模板標記
    需要用到的標簽:<tiles:insert >
    <tiles:insert>的作用類似于方法中的形參,該標記將被調用到該模板的頁面使用<tiles:insert />和<tiles:put />標記指定的具體信息。
    下面會有一個例子:
    Template.jsp模板頁:
    <%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
    <html>
    <body>
    <table width="80%" higth="80%" bordercolor="#ffddff">
     <tr height="15%" bgcolor="#ddbbcc">
      <td>
       <tiles:insert attribute="header" />
      </td>
     </tr>
     <tr height="50%" bgcolor="#ffaaaa">
      <td>
       <tiles:insert attribute="content" />
      </td>
     </tr>
     <tr height="15%" bgcolor="#ccccff">
      <td>
       <tiles:insert attribute="footer" />
      </td>
     </tr>
    </table>
    </body>
    </html>

    關鍵的show.jsp

    <%@page contentType="text/html;charset=gb2312" language="java"%>
    <%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>

    <tiles:insert page="Template.jsp">
     <tiles:put name="header" value="A.jsp"></tiles:put>
     <tiles:put name="content" value="B.jsp"></tiles:put>
     <tiles:put name="footer" value="C.jsp"></tiles:put>
    </tiles:insert>


    A.jsp部分,b.jsp和c.jsp略過
    <%@page contentType="text/html;charset=gb2312" language="java"%>
    <%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
    演示信息,表頭部分

    posted @ 2007-10-30 22:48 我的Java工作經歷 閱讀(2033) | 評論 (0)編輯 收藏

    流程控制包括轉發標記<logic:forward>

    重定向標記<logic:redirect>

    1:其中<logic:forward>標記可以將請求轉發給全局ActionForward指定的響應頁面。此標記只有一個name屬性,

    用來指定全局變量ActionForward的名稱,該屬性必須來自struts應用程序配置文件<global-forwards>元素的某個子元素<forward>的name屬性

    2:<logic:redirect>
    使用HttpServletResponse.sendRedicect()方法實現HTTP頁面重定向的功能。有以下屬性

    forward:映射了資源相對路徑的ActionForward
    href:資源完整的url
    page:資源的相對路徑
    使用這個標記,至少要有forward href page 中的一個屬性,以便明確標明響應重定向到哪個資源
    <logic:redirect href="testlogicBean2.jsp" />
    posted @ 2007-10-30 22:04 我的Java工作經歷 閱讀(278) | 評論 (0)編輯 收藏

    2007年7月25日 #

    JAVA書寫規范

    (這條文章已經被閱讀了364次) 時間:2002年03月08日 18:59 來源:韓偉 原創-IT

    1. 命名

    1.1 Package的名字由一個小寫單詞組成;

    一個特有的包的名字的第一部分總是全部使用小寫字母,

    并應該是頂級域名中的一個,現在有com, edu, gov, mil, net, org,

    或者是在ISO標準3166,1981中定義的兩個字母的國家標識。

    這樣的規則可確定某一目錄分開的組件,部門,項目,或登陸名

    com.sun.eng , com.apple.quicktime.v2 ,org.apache.catalina

     

    1.2 Class/Interface:大寫字母開頭而其他字母都小寫;

    類的名字應是名詞,混合大小寫,每個詞的第一個字母大寫。

    盡量保證你的類的名字簡單并是描述性的。使用完整的單詞-避免

    頭字語和縮寫(除非縮寫比長的格式更廣泛使用,例如URL or HTML)

    class ImageSprite , interface RasterDelegate

     

    1.3 方法應是動詞,混合大小寫,第一個字母小寫,每個內部的詞

    的第一個字母大寫;除了變量,所有的實例、類和類的常量都

    是以小寫字母開頭的混和大小寫。內部的詞以大寫字母開頭。

    變量名字不應以下劃線或美元符$開始,盡管二者都是允許的。

    run() ,runFast() , getBackground()

     

    1.4 變量名字應簡短但有意義。變量名字的選擇應該是可記憶

    的---就是說給普通的人指出它的使用的目的,除非是臨時的。臨時變

    量的一般的名字對于整形變量是i,j,k,m,和n,對于字符是c,d,和e。

    int i;

    char c;

    float myWidth;

     

    1.5 常量:聲明類常量的變量和ANSI常量的名字為下劃線分開的

    大寫字母單詞(應避免ANSI常量,除非為了調試)

    static final int MIN_WIDTH = 4;

    static final int MAX_WIDTH = 999;

     

     

    2. 文件

    2.1 開頭:注釋(name,version,date,copyright),package,import;

    /*

    * Classname

    *

    * Version information

    *

    * Date

    *

    * Copyright notice

    */

    package java.awt;

    import java.awt.peer.CanvasPeer;

     

    2.2 Class/Interface:JavaDoc文檔注釋,體(包含程序、運行和其他注釋);

    變量,實例,方法等:按public,protect,private排列;盡量少用public。

    參見最后example

     

     

    3. 縮進

    3.1 避免每行多于80 個字符,逗號后或運算符前斷開,

    someMethod(longExpression1, longExpression2, longExpression3,

    longExpression4, longExpression5);

     

    var = someMethod1(longExpression1,

    someMethod2(longExpression2,

    longExpression3));

     

    3.2 較高級的斷開比較低級的斷開更好,新行應與同級

    上一行的開頭對齊;以下是斷開算術式的兩個例子。

    第一個較好,因為斷開出現在算術式以外,處于較高一級。

    longName1 = longName2 * (longName3 + longName4 - longName5)

    + 4 * longname6; // PREFER

     

    longName1 = longName2 * (longName3 + longName4

    - longName5) + 4 * longname6; // AVOID

     

     

    3.3 縮排的一個單位應使用4 個空格,不使用制表符而盡量使用空格。

    通常語句使用8個空格縮進,就要折行,由于傳統的(4個空格)

    縮進使觀察程序體比較難。例如:

    if ((condition1 && condition2)

    || (condition3 && condition4)

    ||!(condition5 && condition6)) { file://BAD WRAPS

    doSomethingAboutIt(); file://MAKE THIS LINE EASY TO MISS

    }

     

    file://USE THIS INDENTATION INSTEAD

    if ((condition1 && condition2)

    || (condition3 && condition4)

    ||!(condition5 && condition6)) {

    doSomethingAboutIt();

    }

     

     

    4. 注釋,Java程序有兩類注釋:文檔注釋和執行注釋。

    4.1 文檔注釋只有java具有,/**...*/。能夠被javadoc 工具生成HTML文檔,

    描述類,接口,構造器,方法和字段,相當于使用指南。

    /**

    * Class description goes here.

    *

    * @version 1.82 18 Mar 1999

    * @author Firstname Lastname

    */

     

    4.2 執行注釋是那些在使用在C++中的/*...*/和//。目的為了理解程序和運行,

    包括不適合于文檔注釋的內容,塊狀或一行,使用/*...*/,注釋程序可使用//,

    也可放在短行后面,盡量對齊。

    /*

    * @(#)Blah.java 1.82 99/03/18

    *

    * Copyright (c) 1994-1999 Sun Microsystems, Inc.

    * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.

    * All rights reserved.

    *

    * This software is the confidential and proprietary information of Sun

    * Microsystems, Inc. ("Confidential Information"). You shall not

    * disclose such Confidential Information and shall use it only in

    * accordance with the terms of the license agreement you entered into

    * with Sun.

    */

     

    /* A class implementation comment can go here. */

    // implementation comment

     

     

    5. 聲明declaration

    5.1 每行一個聲明,加以注釋;

    int level; // indentation level

    int size; // size of table

     

    5.2 不要在同一行放置不同的類型;

    int foo, fooarray[]; file://WRONG!

     

    5.3 只在塊的開始處,放置聲明;

    第一次使用時再聲明,增強代碼的可移植性。

    if (condition) {

    int int2 = 0; // beginning of "if" block

    ...

    }

    for (int i = 0; i < maxLoops; i++) { ... }

     

    5.4 方法后緊跟"(" ,"{"出現在行尾。

    Sample(int i, int j) {

    ivar1 = i;

    ivar2 = j;

    }

     

     

    6. 語句

    6.1 每行最多包括一個語句;

    argv++; // Correct

    argc--; // Correct

    argv++; argc--; // AVOID!

    if (condition) {

    statements;

    } else {

    statements;

    }

    for (initialization; condition; update) {

    statements;

    }

     

    6.2 比較重要的一個:

    try {

    statements;

    }catch (ExceptionClass e) {

    statements;

    }

     

     

    7. 空格

    7.1 利用空行分隔代碼段來提高可讀性;

    7.2 使用空行:類,接口,方法之間,在一個方法的本地變量和它的第一個語句間;

    7.3 被一個圓括號跟著的關鍵字應被一個空格所分開,

    例"while (true) { ",

    但方法不分開。

    7.4 參數列表中的逗號之后使用一個空格。

    public void doSomethingElse(Object someParam, String twoParam)

    7.5 二進制的操作符與數以空格分開,例"a = (a + b) / (c * d);" 。

     

     

    8. 其它

    8.1 避免使用一個對象來訪問一個類的(靜態)變量或方法。

    而是使用一個類的名字;

    classMethod(); file://OK

    AClass.classMethod(); file://OK

    anObject.classMethod(); file://AVOID!

     

    8.2 避免分配多個變量給同樣值在一個單獨的語句中;

    fooBar.fChar = barFoo.lchar = 'c'; // AVOID!

     

    8.3 適當使用()和{}來分隔運算和程序。

     

     

    9. 性能有關 (優化代碼,調試,運行)

    避免太多的使用 synchronized 關鍵字 ;

    盡量使用 StringBuffer 對象;

    盡量不要混合使用AWT 和 Swing 組件,等等。

     

     

    下面是一個參考范例。

    /*

    * @(#)Blah.java 1.82 99/03/18

    *

    * Copyright (c) 1994-1999 Sun Microsystems, Inc.

    * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.

    * All rights reserved.

    *

    * This software is the confidential and proprietary information of Sun

    * with Sun.....

    */

     

     

    package java.blah;

     

    import java.blah.blahdy.BlahBlah;

     

    /**

    * Class description goes here.

    *

    * @version 1.82 18 Mar 1999

    * @author Firstname Lastname

    */

    public class Blah extends SomeClass {

    /* 執行注釋. */

     

    /** classVar1 文檔注釋*/

    public static int classVar1;

     

    /**

    * classVar2 多于一行的文檔注釋

    * 注釋

    */

    private static Object classVar2;

     

    /** instanceVar1 文檔注釋 */

    public Object instanceVar1;

     

    /** instanceVar2 文檔注釋 */

    protected int instanceVar2;

     

    /** instanceVar3 文檔注釋 */

    private Object[] instanceVar3;

     

    /**

    * ...構造器 Blah 文檔注釋...

    */

    public Blah() {

    // ...執行注釋 goes here...

    }

     

    /**

    * ...方法 doSomething 文檔注釋...

    */

    public void doSomething() {

    // ...執行注釋 goes here...

    }

     

    /**

    * ...方法 doSomethingElse文檔注釋..

    * @param someParam參數描述

    */

    public void doSomethingElse(Object someParam) {

    // ...執行注釋goes here...

    }

    }

    posted @ 2007-07-25 14:49 我的Java工作經歷 閱讀(602) | 評論 (1)編輯 收藏

    myeclipse4.0GA似乎必須要jdk1.5以上版本才可以(因為我開始安裝了1.4后,連啟動都有問題)。

    我現在的環境是eclipse3.2+myeclipse4.0GA,總算可以打開了,不過在打開jsp文件時仍然有問題。
    Unable to create this part due to an internal error. Reason for the failure: Widget is disposed

    org.eclipse.swt.SWTException: Widget is disposed
     at org.eclipse.swt.SWT.error(SWT.java:3374)
     at org.eclipse.swt.SWT.error(SWT.java:3297)
     at org.eclipse.swt.SWT.error(SWT.java:3268)
     at org.eclipse.swt.widgets.Widget.error(Widget.java:435)
     at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:330)
     at org.eclipse.swt.widgets.Control.setLayoutData(Control.java:2386)
     at com.genuitec.eclipse.webdesigner3.design.DesignEditSystem.createDesignView(DesignEditSystem.java:72)
     at com.genuitec.eclipse.webdesigner3.WebDesigner3.createDesignView(WebDesigner3.java:73)
     at com.genuitec.eclipse.webdesigner3.editors.WebDesignerMultiPageEditor.createDesignView(WebDesignerMultiPageEditor.java:392)
     at com.genuitec.eclipse.webdesigner3.editors.WebDesignerMultiPageEditor.createDesignPage(WebDesignerMultiPageEditor.java:364)
     at com.genuitec.eclipse.webdesigner3.editors.WebDesignerMultiPageEditor.createPages(WebDesignerMultiPageEditor.java:286)
     at org.eclipse.ui.part.MultiPageEditorPart.createPartControl(MultiPageEditorPart.java:276)
     at org.eclipse.ui.internal.EditorReference.createPartHelper(EditorReference.java:596)
     at org.eclipse.ui.internal.EditorReference.createPart(EditorReference.java:372)
     at org.eclipse.ui.internal.WorkbenchPartReference.getPart(WorkbenchPartReference.java:566)
     at org.eclipse.ui.internal.PartPane.setVisible(PartPane.java:290)
     at org.eclipse.ui.internal.presentations.PresentablePart.setVisible(PresentablePart.java:140)
     at org.eclipse.ui.internal.presentations.util.PresentablePartFolder.select(PresentablePartFolder.java:268)
     at org.eclipse.ui.internal.presentations.util.LeftToRightTabOrder.select(LeftToRightTabOrder.java:65)
     at org.eclipse.ui.internal.presentations.util.TabbedStackPresentation.selectPart(TabbedStackPresentation.java:394)
     at org.eclipse.ui.internal.PartStack.refreshPresentationSelection(PartStack.java:1144)
     at org.eclipse.ui.internal.PartStack.setSelection(PartStack.java:1097)
     at org.eclipse.ui.internal.PartStack.showPart(PartStack.java:1311)
     at org.eclipse.ui.internal.PartStack.add(PartStack.java:455)
     at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:102)
     at org.eclipse.ui.internal.PartStack.add(PartStack.java:441)
     at org.eclipse.ui.internal.EditorStack.add(EditorStack.java:111)
     at org.eclipse.ui.internal.EditorSashContainer.addEditor(EditorSashContainer.java:60)
     at org.eclipse.ui.internal.EditorAreaHelper.addToLayout(EditorAreaHelper.java:217)
     at org.eclipse.ui.internal.EditorAreaHelper.addEditor(EditorAreaHelper.java:207)
     at org.eclipse.ui.internal.EditorManager.createEditorTab(EditorManager.java:819)
     at org.eclipse.ui.internal.EditorManager.openEditorFromDescriptor(EditorManager.java:718)
     at org.eclipse.ui.internal.EditorManager.openEditor(EditorManager.java:679)
     at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2586)
     at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2521)
     at org.eclipse.ui.internal.WorkbenchPage.access$10(WorkbenchPage.java:2513)
     at org.eclipse.ui.internal.WorkbenchPage$9.run(WorkbenchPage.java:2498)
     at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:67)
     at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2493)
     at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2478)
     at org.eclipse.ui.ide.IDE.openEditor(IDE.java:388)
     at org.eclipse.ui.ide.IDE.openEditor(IDE.java:350)
     at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:275)
     at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:139)
     at org.eclipse.jdt.internal.ui.actions.OpenActionUtil.open(OpenActionUtil.java:49)
     at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:190)
     at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:174)
     at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:267)
     at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:243)
     at org.eclipse.jdt.internal.ui.packageview.PackageExplorerActionGroup.handleOpen(PackageExplorerActionGroup.java:306)
     at org.eclipse.jdt.internal.ui.packageview.PackageExplorerPart$4.open(PackageExplorerPart.java:651)
     at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:817)
     at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
     at org.eclipse.core.runtime.Platform.run(Platform.java:843)
     at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:44)
     at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:149)
     at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:815)
     at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1069)
     at org.eclipse.jface.viewers.StructuredViewer$6.handleOpen(StructuredViewer.java:1168)
     at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:249)
     at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.java:243)
     at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:283)
     at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
     at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
     at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
     at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
     at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
     at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
     at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
     at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
     at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
     at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
     at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
     at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
     at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
     at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
     at java.lang.reflect.Method.invoke(Unknown Source)
     at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336)
     at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
     at org.eclipse.core.launcher.Main.run(Main.java:977)
     at org.eclipse.core.launcher.Main.main(Main.java:952)

    網絡上搜索得到的信息是myeclipse的版本可能和eclipse存在沖突,導致myeclipse的jsp頁面設計器無法正確打開,因此,在國外的論壇上,都建議還是使用eclipse3.0來寫jsp。

    或者,就是不要使用myeclipse的頁面設計器(反正對寫代碼的人而言更多是使用代碼視圖),因此要將jsp的默認打開方式改成代碼試圖:
    window---->perferences----->General------->editors------>file associations
    選擇jsp------->選擇相應的editor 為default。也就是把myeclispe jsp editor 設為default(而不是myeclispe visual jsp editor)

    posted @ 2007-07-25 14:44 我的Java工作經歷 閱讀(756) | 評論 (0)編輯 收藏

    僅列出標題  
    主站蜘蛛池模板: 国产精品亚洲片在线va| 久久亚洲精品成人av无码网站| 亚洲国产成AV人天堂无码| 久久免费精品一区二区| 中文字幕第一页亚洲| 国产va免费观看| 久久亚洲AV永久无码精品| eeuss草民免费| 国产AV无码专区亚洲精品| 日韩精品在线免费观看| 色噜噜综合亚洲av中文无码| 日韩电影免费在线观看中文字幕| 久久精品亚洲一区二区| 最近最新高清免费中文字幕| 中文字幕在线观看亚洲| 手机看黄av免费网址| 亚洲色图激情文学| 日本高清免费网站| 美女视频黄a视频全免费网站一区| 亚洲高清国产拍精品青青草原| 一级做a毛片免费视频| 国产亚洲美女精品久久久2020| a视频免费在线观看| 亚洲综合精品香蕉久久网97| 99国产精品永久免费视频| 亚洲国产精品美女久久久久| 亚洲欧洲国产成人综合在线观看| 国产成人免费AV在线播放 | 成年大片免费高清在线看黄| 亚洲综合久久夜AV | 无码人妻一区二区三区免费看| 亚洲成人福利网站| 国产在线不卡免费播放| 99久久免费国产精品热| 亚洲jjzzjjzz在线播放| 亚洲福利中文字幕在线网址| 91精品啪在线观看国产线免费| 亚洲综合国产成人丁香五月激情| 亚洲 另类 无码 在线| 最近最新高清免费中文字幕| 婷婷国产偷v国产偷v亚洲|