FreeMan

          Java是條不歸路……

            BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            4 隨筆 :: 1 文章 :: 2 評(píng)論 :: 0 Trackbacks

          2007年10月30日 #

          1:創(chuàng)建模板標(biāo)記
          需要用到的標(biāo)簽:<tiles:insert >
          <tiles:insert>的作用類似于方法中的形參,該標(biāo)記將被調(diào)用到該模板的頁(yè)面使用<tiles:insert />和<tiles:put />標(biāo)記指定的具體信息。
          下面會(huì)有一個(gè)例子:
          Template.jsp模板頁(yè):
          <%@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>

          關(guān)鍵的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略過(guò)
          <%@page contentType="text/html;charset=gb2312" language="java"%>
          <%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
          演示信息,表頭部分

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

          流程控制包括轉(zhuǎn)發(fā)標(biāo)記<logic:forward>

          重定向標(biāo)記<logic:redirect>

          1:其中<logic:forward>標(biāo)記可以將請(qǐng)求轉(zhuǎn)發(fā)給全局ActionForward指定的響應(yīng)頁(yè)面。此標(biāo)記只有一個(gè)name屬性,

          用來(lái)指定全局變量ActionForward的名稱,該屬性必須來(lái)自struts應(yīng)用程序配置文件<global-forwards>元素的某個(gè)子元素<forward>的name屬性

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

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

          2007年7月25日 #

          JAVA書寫規(guī)范

          (這條文章已經(jīng)被閱讀了364次) 時(shí)間:2002年03月08日 18:59 來(lái)源:韓偉 原創(chuàng)-IT

          1. 命名

          1.1 Package的名字由一個(gè)小寫單詞組成;

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

          并應(yīng)該是頂級(jí)域名中的一個(gè),現(xiàn)在有com, edu, gov, mil, net, org,

          或者是在ISO標(biāo)準(zhǔn)3166,1981中定義的兩個(gè)字母的國(guó)家標(biāo)識(shí)。

          這樣的規(guī)則可確定某一目錄分開的組件,部門,項(xiàng)目,或登陸名

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

           

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

          類的名字應(yīng)是名詞,混合大小寫,每個(gè)詞的第一個(gè)字母大寫。

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

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

          class ImageSprite , interface RasterDelegate

           

          1.3 方法應(yīng)是動(dòng)詞,混合大小寫,第一個(gè)字母小寫,每個(gè)內(nèi)部的詞

          的第一個(gè)字母大寫;除了變量,所有的實(shí)例、類和類的常量都

          是以小寫字母開頭的混和大小寫。內(nèi)部的詞以大寫字母開頭。

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

          run() ,runFast() , getBackground()

           

          1.4 變量名字應(yīng)簡(jiǎn)短但有意義。變量名字的選擇應(yīng)該是可記憶

          的---就是說(shuō)給普通的人指出它的使用的目的,除非是臨時(shí)的。臨時(shí)變

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

          int i;

          char c;

          float myWidth;

           

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

          大寫字母單詞(應(yīng)避免ANSI常量,除非為了調(diào)試)

          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文檔注釋,體(包含程序、運(yùn)行和其他注釋);

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

          參見最后example

           

           

          3. 縮進(jìn)

          3.1 避免每行多于80 個(gè)字符,逗號(hào)后或運(yùn)算符前斷開,

          someMethod(longExpression1, longExpression2, longExpression3,

          longExpression4, longExpression5);

           

          var = someMethod1(longExpression1,

          someMethod2(longExpression2,

          longExpression3));

           

          3.2 較高級(jí)的斷開比較低級(jí)的斷開更好,新行應(yīng)與同級(jí)

          上一行的開頭對(duì)齊;以下是斷開算術(shù)式的兩個(gè)例子。

          第一個(gè)較好,因?yàn)閿嚅_出現(xiàn)在算術(shù)式以外,處于較高一級(jí)。

          longName1 = longName2 * (longName3 + longName4 - longName5)

          + 4 * longname6; // PREFER

           

          longName1 = longName2 * (longName3 + longName4

          - longName5) + 4 * longname6; // AVOID

           

           

          3.3 縮排的一個(gè)單位應(yīng)使用4 個(gè)空格,不使用制表符而盡量使用空格。

          通常語(yǔ)句使用8個(gè)空格縮進(jìn),就要折行,由于傳統(tǒng)的(4個(gè)空格)

          縮進(jìn)使觀察程序體比較難。例如:

          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程序有兩類注釋:文檔注釋和執(zhí)行注釋。

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

          描述類,接口,構(gòu)造器,方法和字段,相當(dāng)于使用指南。

          /**

          * Class description goes here.

          *

          * @version 1.82 18 Mar 1999

          * @author Firstname Lastname

          */

           

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

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

          也可放在短行后面,盡量對(duì)齊。

          /*

          * @(#)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 每行一個(gè)聲明,加以注釋;

          int level; // indentation level

          int size; // size of table

           

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

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

           

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

          第一次使用時(shí)再聲明,增強(qiáng)代碼的可移植性。

          if (condition) {

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

          ...

          }

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

           

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

          Sample(int i, int j) {

          ivar1 = i;

          ivar2 = j;

          }

           

           

          6. 語(yǔ)句

          6.1 每行最多包括一個(gè)語(yǔ)句;

          argv++; // Correct

          argc--; // Correct

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

          if (condition) {

          statements;

          } else {

          statements;

          }

          for (initialization; condition; update) {

          statements;

          }

           

          6.2 比較重要的一個(gè):

          try {

          statements;

          }catch (ExceptionClass e) {

          statements;

          }

           

           

          7. 空格

          7.1 利用空行分隔代碼段來(lái)提高可讀性;

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

          7.3 被一個(gè)圓括號(hào)跟著的關(guān)鍵字應(yīng)被一個(gè)空格所分開,

          例"while (true) { ",

          但方法不分開。

          7.4 參數(shù)列表中的逗號(hào)之后使用一個(gè)空格。

          public void doSomethingElse(Object someParam, String twoParam)

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

           

           

          8. 其它

          8.1 避免使用一個(gè)對(duì)象來(lái)訪問(wèn)一個(gè)類的(靜態(tài))變量或方法。

          而是使用一個(gè)類的名字;

          classMethod(); file://OK

          AClass.classMethod(); file://OK

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

           

          8.2 避免分配多個(gè)變量給同樣值在一個(gè)單獨(dú)的語(yǔ)句中;

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

           

          8.3 適當(dāng)使用()和{}來(lái)分隔運(yùn)算和程序。

           

           

          9. 性能有關(guān) (優(yōu)化代碼,調(diào)試,運(yùn)行)

          避免太多的使用 synchronized 關(guān)鍵字 ;

          盡量使用 StringBuffer 對(duì)象;

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

           

           

          下面是一個(gè)參考范例。

          /*

          * @(#)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 {

          /* 執(zhí)行注釋. */

           

          /** classVar1 文檔注釋*/

          public static int classVar1;

           

          /**

          * classVar2 多于一行的文檔注釋

          * 注釋

          */

          private static Object classVar2;

           

          /** instanceVar1 文檔注釋 */

          public Object instanceVar1;

           

          /** instanceVar2 文檔注釋 */

          protected int instanceVar2;

           

          /** instanceVar3 文檔注釋 */

          private Object[] instanceVar3;

           

          /**

          * ...構(gòu)造器 Blah 文檔注釋...

          */

          public Blah() {

          // ...執(zhí)行注釋 goes here...

          }

           

          /**

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

          */

          public void doSomething() {

          // ...執(zhí)行注釋 goes here...

          }

           

          /**

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

          * @param someParam參數(shù)描述

          */

          public void doSomethingElse(Object someParam) {

          // ...執(zhí)行注釋goes here...

          }

          }

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

          myeclipse4.0GA似乎必須要jdk1.5以上版本才可以(因?yàn)槲议_始安裝了1.4后,連啟動(dòng)都有問(wèn)題)。

          我現(xiàn)在的環(huán)境是eclipse3.2+myeclipse4.0GA,總算可以打開了,不過(guò)在打開jsp文件時(shí)仍然有問(wèn)題。
          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)

          網(wǎng)絡(luò)上搜索得到的信息是myeclipse的版本可能和eclipse存在沖突,導(dǎo)致myeclipse的jsp頁(yè)面設(shè)計(jì)器無(wú)法正確打開,因此,在國(guó)外的論壇上,都建議還是使用eclipse3.0來(lái)寫jsp。

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

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

          僅列出標(biāo)題  
          主站蜘蛛池模板: 永昌县| 阳高县| 洪湖市| 古丈县| 潜山县| 蒲江县| 泌阳县| 和田市| 宁南县| 西丰县| 宾川县| 乡宁县| 漠河县| 余姚市| 盐城市| 汾西县| 三河市| 河北省| 玛纳斯县| 郎溪县| 宝应县| 博野县| 错那县| 杭州市| 咸阳市| 合川市| 胶南市| 房产| 丰顺县| 河津市| 老河口市| 周宁县| 娱乐| 义乌市| 康定县| 永寿县| 高雄市| 奉化市| 辰溪县| 沙洋县| 来凤县|