毫无废话: 从0开始一点一滴用java开发自己的B/S构架--1.2

来源:互联网 发布:精英特软件安卓版 编辑:程序博客网 时间:2024/04/27 16:48

hellochina一下

所有程序介绍的书第一个例子恐怕都是helloworld,我们来个hellochian如何

在你的tomcat的webapps(以后你的所有应用都放在webapps里面啦)下建立一个文件夹,就叫myOne

myOne下建个文件夹WEB-INF 

WEB-INF下建两个文件夹:classeslib

照着写吧,不要问为什么?想你的程序运行起来,就别写错了.

 

用你的记事本写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+cctrl+v会吧?

什么,看不懂?我有叫你看明白吗?

把你的tomcat重新启动(就是关了,再打开)一下吧.

 

在你的ie地址栏输入: http://localhost:8080/myOne/hello.jsp

好了                                                                                                                                   

看到结果了吧。就是一句:hellochina

怎么,觉得太麻烦了?为写这么简单个东东,搞这么多的名堂,太“脱裤子放屁”了吧?

没有人叫你用这个来写一个helloworld的才程序啊。不要觉得它简单,学问可大着呢!好了,当你看到这个例子的结果的时候,那就该对你说:欢迎你,你已经看到“用java开发三层结构程序”的门了。重申:你只是看到门了,还没走到门边,就更别说入门了,继续努力吧,好戏还在后头呢!

本章后话

还记得我们第一个例子的目录结构吗?一定要把你的应用放在tomcatwebapps下面,而且你的应用中一定要有WEB-INF,在WEB-INF下一定要有web.xml,当然在WEB-INF下的文件夹classes和文件夹lib对于你现在来说还没什么用,但是你就先这样照葫芦画瓢吧。将来把你的程序的JAVA类放在classes里,把需要的JAR包放在lib里。

为了让你把目录结构看的更明白,我画了个很丑的东西(圆柱表示文件夹,圆角矩形表示文件)。

好了,希望你的myOne程序一切顺利。