严重警告:知道tomcat的人不要往下看<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
开场白:比较枯燥、相当无味
开始了
需要什么?
Jdk和tomcat
我的版本: j2sdk<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">1.4.1</chsdate>和tomcat-4.1.18
什么,还没有这两个东东?那就请您不要在往下看了,赶快狗狗去或者email去.
安装和配置
把你的jdk装了吧,就装在你的d盘如何? D:\j2sdk<chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">1.4.1</chsdate>
把tom先生的猫(tomcat)也解压缩了吧,也放在d盘算了, D:\tomcat-<chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">4.1.18</chsdate>
设置你的系统环境变量,为了让我的这个成为傻瓜式的,请原谅我的罗嗦.
我的电脑—右键—高级—环境变量—系统变量—
新建
变量名: java_home
变量值: D:\j2sdk<chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">1.4.1</chsdate>
编辑
变量名: Path
变量值: D:\j2sdk<chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">1.4.1</chsdate>\bin\;(在最前面加)
ok,确定就行了
启动
在你的D:\tomcat-<chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">4.1.18</chsdate>\bin\下找到startup.bat,用老鼠点她两下,让她运行起来吧.
在你的ie地址栏输入: http://localhost:8080/
看到
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_s1026" style="WIDTH: 414pt; HEIGHT: 154.1pt; mso-position-horizontal-relative: char; mso-position-vertical-relative: line" fillcolor="#00e4a8" type="#_x0000_t75"><font size="2"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5CADMINI~1%5CLOCALS~1%5CTemp%5Cmsohtml1%5C05%5Cclip_image001.png"></imagedata><shadow color="#1c1c1c"></shadow><?xml:namespace prefix = w ns = "urn:schemas-microsoft-com:office:word" /><wrap type="none"></wrap><anchorlock></anchorlock></font></shape>
恭喜你,你的配置工作做好了.
来hellochina一下
所有程序介绍的书第一个例子恐怕都是helloworld,我们来个hellochian如何
在你的tomcat下建立一个文件夹,就叫myOne吧
myOne下建个文件夹WEB-INF
WEB-INF下建两个文件夹:classes和lib
照着写吧,不要问为什么?想你的程序运行起来,就别写错了.
用你的记事本写hello.jsp放到你的myOne下面吧
<html>hellochina</html>
什么,还不知道html为何物?那你还是学习学习吧,写的不好,至少看的明白吧。
用你的记事本写web.xml放到WEB-INF下吧
<?xml version="1.0" encoding="gb2312"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<!-- Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<!-- Specify servlet class to use:
- Struts1.0.x: ActionComponentServlet
- Struts1.1: ActionServlet
- no Struts: TilesServlet
-->
<!-- <servlet-class>org.apache.struts.tiles.ActionComponentServlet</servlet-class> -->
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<!-- <servlet-class>org.apache.struts.tiles.TilesServlet</servlet-class> -->
<!-- Tiles Servlet parameter
Specify configuration file names. There can be several comma
separated file names
-->
<!-- Tiles Servlet parameter
Specify Tiles debug level.
O : no debug information
1 : debug information
2 : more debug information
-->
<init-param>
<param-name>definitions-debug</param-name>
<param-value>1</param-value>
</init-param>
<!-- Tiles Servlet parameter
Specify Digester debug level. This value is passed to Digester
O : no debug information
1 : debug information
2 : more debug information
-->
<init-param>
<param-name>definitions-parser-details</param-name>
<param-value>0</param-value>
</init-param>
<!-- Tiles Servlet parameter
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header.
false : no validation
-->
<init-param>
<param-name>definitions-parser-validate</param-name>
<param-value>true</param-value>
</init-param>
<!-- Struts configuration, if Struts is used -->
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>validate</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list>
<!-- Struts Tag Library Descriptor -->
</web-app>
什么,太长了,写的辛苦?ctrl+c和ctrl+v会吧?
什么,看不懂?我有叫你看明白吗?
把你的tomcat重新启动(就是关了,再打开)一下吧.
在你的ie地址栏输入: http://localhost:8080/hello.jsp
好了
看到结果了吧。就是一句:hellochina。
怎么,觉得太麻烦了?为写这么简单个东东,搞这么多的名堂,太“脱裤子放屁”了吧?
没有人叫你用这个来写一个helloworld的才程序啊。不要觉得它简单,学问可大着呢!好了,当你看到这个例子的结果的时候,那就该对你说:欢迎你,你已经看到“用java开发三层结构程序”的门了。重申:你只是看到门了,还没走到门边,就更别说入门了,继续努力吧,好戏还在后头呢!
本章后话
还记得我们第一个例子的目录结构吗?一定要把你的应用放在tomcat的webapps下面,而且你的应用中一定要有WEB-INF,在WEB-INF下一定要有web.xml,当然在WEB-INF下的文件夹classes和文件夹lib对于你现在来说还没什么用,但是你就先这样照葫芦画瓢吧。将来把你的程序的JAVA类放在classes里,把需要的JAR包放在lib里。
为了让你把目录结构看的更明白,我画了个很丑的东西(圆柱表示文件夹,圆角矩形表示文件)。
好了,希望你的myOne程序一切顺利。
<group id="_x0000_s1027" style="MARGIN-TOP: 7.8pt; Z-INDEX: 2; LEFT: 0px; MARGIN-LEFT: 27pt; WIDTH: 324pt; POSITION: absolute; HEIGHT: 132.6pt; TEXT-ALIGN: left" coordsize="6480,2652" coordorigin="2340,13296"><shapetype id="_x0000_t132" path="m10800,qx,3391l,18209qy10800,21600,21600,18209l21600,3391qy10800,xem,3391nfqy10800,6782,21600,3391e" o:spt="132" coordsize="21600,21600"><path o:connecttype="custom" gradientshapeok="t" o:extrusionok="f" textboxrect="0,6782,21600,18209" o:connectangles="270,270,180,90,0" o:connectlocs="10800,6782;10800,0;0,10800;10800,21600;21600,10800"></path></shapetype><shape id="_x0000_s1028" style="LEFT: 2520px; WIDTH: 900px; POSITION: absolute; TOP: 13452px; HEIGHT: 1404px" type="#_x0000_t132"><font size="2"></font></shape><shape id="_x0000_s1029" style="LEFT: 4140px; WIDTH: 1260px; POSITION: absolute; TOP: 13296px; HEIGHT: 780px" type="#_x0000_t132"><font size="2"></font></shape><shape id="_x0000_s1030" style="LEFT: 6480px; WIDTH: 900px; POSITION: absolute; TOP: 13452px; HEIGHT: 624px" type="#_x0000_t132"><font size="2"></font></shape><shape id="_x0000_s1031" style="LEFT: 6480px; WIDTH: 900px; POSITION: absolute; TOP: 14388px; HEIGHT: 624px" type="#_x0000_t132"><font size="2"></font></shape><shapetype id="_x0000_t176" path="m@0,qx0@0l0@2qy@0,21600l@1,21600qx21600@2l21600@0qy@1,xe" o:spt="176" coordsize="21600,21600" adj="2700"><stroke joinstyle="miter"></stroke><formulas><f eqn="val #0"></f><f eqn="sum width 0 #0"></f><f eqn="sum height 0 #0"></f><f eqn="prod @0 2929 10000"></f><f eqn="sum width 0 @3"></f><f eqn="sum height 0 @3"></f><f eqn="val width"></f><f eqn="val height"></f><f eqn="prod width 1 2"></f><f eqn="prod height 1 2"></f></formulas><path o:connecttype="custom" gradientshapeok="t" textboxrect="@3,@3,@4,@5" o:connectlocs="@8,0;0,@9;@8,@7;@6,@9" limo="10800,10800"></path></shapetype><shape id="_x0000_s1032" style="LEFT: 6300px; WIDTH: 1260px; POSITION: absolute; TOP: 15168px; HEIGHT: 468px" type="#_x0000_t176"><font size="2"></font></shape><roundrect id="_x0000_s1033" style="LEFT: 4140px; WIDTH: 1260px; POSITION: absolute; TOP: 14700px; HEIGHT: 624px" arcsize="10923f"><font size="2"></font></roundrect><line id="_x0000_s1034" style="POSITION: absolute; flip: y" to="4140,14076" from="3420,13920"><stroke endarrow="block"><font size="2"></font></stroke></line><line id="_x0000_s1035" style="POSITION: absolute" to="4140,14856" from="3420,14388"><stroke endarrow="block"><font size="2"></font></stroke></line><line id="_x0000_s1036" style="POSITION: absolute" to="6480,13920" from="5400,13920"><stroke endarrow="block"><font size="2"></font></stroke></line><line id="_x0000_s1037" style="POSITION: absolute" to="6480,14700" from="5400,13920"><stroke endarrow="block"><font size="2"></font></stroke></line><line id="_x0000_s1038" style="POSITION: absolute" to="6300,15480" from="5400,13920"><stroke endarrow="block"><font size="2"></font></stroke></line><shapetype id="_x0000_t202" path="m,l,21600r21600,l21600,xe" o:spt="202" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><path o:connecttype="rect" gradientshapeok="t"></path></shapetype><shape id="_x0000_s1039" style="LEFT: 2340px; WIDTH: 1260px; POSITION: absolute; TOP: 15012px; HEIGHT: 468px" stroked="f" type="#_x0000_t202"><textbox style="mso-next-textbox: #_x0000_s1039"><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN"><font size="2">myOne</font></span></p> </div> </td></tr></tbody></table></textbox></shape><shape id="_x0000_s1040" style="LEFT: 4140px; WIDTH: 1260px; POSITION: absolute; TOP: 14232px; HEIGHT: 468px" stroked="f" type="#_x0000_t202"><textbox><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN"><font size="2">WEB-INF</font></span></p> </div> </td></tr></tbody></table></textbox></shape><shape id="_x0000_s1041" style="LEFT: 4140px; WIDTH: 1620px; POSITION: absolute; TOP: 15480px; HEIGHT: 468px" stroked="f" type="#_x0000_t202"><textbox><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN"><font size="2">Hello.jsp</font></span></p> </div> </td></tr></tbody></table></textbox></shape><shape id="_x0000_s1042" style="LEFT: 7560px; WIDTH: 1080px; POSITION: absolute; TOP: 13452px; HEIGHT: 468px" stroked="f" type="#_x0000_t202"><textbox><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN"><font size="2">classes</font></span></p> </div> </td></tr></tbody></table></textbox></shape><shape id="_x0000_s1043" style="LEFT: 7560px; WIDTH: 1080px; POSITION: absolute; TOP: 14388px; HEIGHT: 468px" stroked="f" type="#_x0000_t202"><textbox><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt; TEXT-INDENT: 10.5pt; mso-char-indent-count: 1.0"><span lang="EN"><font size="2">lib</font></span></p> </div> </td></tr></tbody></table></textbox></shape><shape id="_x0000_s1044" style="LEFT: 7740px; WIDTH: 1080px; POSITION: absolute; TOP: 15168px; HEIGHT: 468px" stroked="f" type="#_x0000_t202"><textbox><table cellspacing="0" cellpadding="0" width="100%"><tbody><tr><td style="BORDER-RIGHT: #d4d0c8; BORDER-TOP: #d4d0c8; BORDER-LEFT: #d4d0c8; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"> <div> <p class="MsoNormal" style="MARGIN: 0cm 0cm 0pt"><span lang="EN"><font size="2">Web.xml</font></span></p> </div> </td></tr></tbody></table></textbox></shape></group>