`
thedigger
  • 浏览: 24396 次
社区版块
存档分类
最新评论

web应用开发入门(1)-使用eclipse搭建tomcat下web应用项目详细步骤

阅读更多


以下是对第一次学习web应用开发的朋友而写。具体步骤如下:

 

1、建立基于j2ee的web应用开发工具目录 c:\j2ee

 

2、安装JDKJRE

2.1、下载JDK,地址为:

http://www.java.net/download/jdk6/6u32/promoted/b03/binaries/jdk-6u32-ea-bin-b03-windows-amd64-29_feb_2012.exe

 

2.2、安装JDKJRE

运行jdk-6u32-ea-bin-b03-windows-amd64-29_feb_2012.exe,在安装过程中将JDK安装于C:\j2ee\Java\jdk1.6.0_32\下,将JRE安装于C:\j2ee\Java\jre6\下。

 

3、安装tomcat

3.1、下载tomcat,地址为:

http://mirror.bjtu.edu.cn/apache/tomcat/tomcat-6/v6.0.35/bin/apache-tomcat-6.0.35.exe

 

3.2、安装tomcat

运行apache-tomcat-6.0.35.exe,在安装过程中选择jre路径为C:\j2ee\Java\jre6。

 


 点击Next按钮



 点击Install按钮完成tomcat的安装。

 

4、安装开发支持包

... 

 

5、安装eclipse

5.1、下载eclipse,地址为http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-win32-x86_64.zip&url=http://mirrors.ustc.edu.cn/eclipse/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-win32-x86_64.zip&mirror_id=1093

 

5.2、安装eclipse

使用winrar压缩工具,将 eclipse-jee-indigo-SR2-win32-x86_64.zip 解压到  C:\j2ee下,\eclipse 目录下

 

5.3、适当修改eclipse启动配置文件C:\j2ee\eclipse\eclipse.ini中的内存参数,比如说如下:

 

-Xms512m

-Xmx1536m

-XX:PermSize=256m

-XX:MaxPermSize=768m

 

6、安装用于eclipsetomcat插件

6.1、下载tomcat插件,地址为:

 

http://www.eclipsetotale.com/tomcatPlugin/tomcatPluginV33.zip

 

6.2、安装tomcat插件

使用winrar压缩工具,将tomcatPluginV33.zip解压到eclipse的插件目录C:\j2ee\eclipse\plugins下。

 

7、执行C:\j2ee\eclipse\eclipse.exe

7.1、在启动过程中,设置workspace文件夹,比如说c:\workspace


 

7.2、检查工具栏中有3tomcat插件相关的图标按钮。


 

7.3、配置tomcat可以在eclipse中启用停用的选项

菜单路径:Window > Preferences


  • 鼠标左键单击左边列表框中的Tomcat
  • 鼠标左键单击右上的Tomcat版本,选择Version 6.x
  • 填写Tomcat安装目录c:\j2ee\Tomcat 6.0
  • 对于Context declaration mode选择单选按钮Server.xml
  • 鼠标左键单击OK按钮
  • 鼠标左键单击eclipse工具栏中的“Start Tomcat”图标按钮,启动tomcat,测试tomcat的配置的正确性


eclipse的控制台中显示的信息如下:

2012-3-20 21:28:41 org.apache.catalina.core.AprLifecycleListener init

信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\j2ee\Java\jre6\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows7Master;C:\Program Files (x86)\Lenovo\Access Connections\;C:\PROGRA~2\IBM\SQLLIB\BIN;C:\PROGRA~2\IBM\SQLLIB\FUNCTION;C:\PROGRA~2\IBM\SQLLIB\SAMPLES\REPL;.

2012-3-20 21:28:42 org.apache.coyote.http11.Http11Protocol init

信息: Initializing Coyote HTTP/1.1 on http-8080

2012-3-20 21:28:42 org.apache.catalina.startup.Catalina load

信息: Initialization processed in 1959 ms

2012-3-20 21:28:42 org.apache.catalina.core.StandardService start

信息: Starting service Catalina

2012-3-20 21:28:42 org.apache.catalina.core.StandardEngine start

信息: Starting Servlet Engine: Apache Tomcat/6.0.35

2012-3-20 21:28:42 org.apache.catalina.startup.HostConfig deployDescriptor

信息: Deploying configuration descriptor host-manager.xml

2012-3-20 21:28:43 org.apache.catalina.startup.HostConfig deployDescriptor

信息: Deploying configuration descriptor manager.xml

2012-3-20 21:28:43 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory docs

2012-3-20 21:28:43 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory examples

2012-3-20 21:28:44 org.apache.catalina.core.ApplicationContext log

信息: ContextListener: contextInitialized()

2012-3-20 21:28:44 org.apache.catalina.core.ApplicationContext log

信息: SessionListener: contextInitialized()

2012-3-20 21:28:44 org.apache.catalina.startup.HostConfig deployDirectory

信息: Deploying web application directory ROOT

2012-3-20 21:28:44 org.apache.coyote.http11.Http11Protocol start

信息: Starting Coyote HTTP/1.1 on http-8080

2012-3-20 21:28:44 org.apache.jk.common.ChannelSocket init

信息: JK: ajp13 listening on /0.0.0.0:8009

2012-3-20 21:28:44 org.apache.jk.server.JkMain start

信息: Jk running ID=0 time=1/79  config=null

2012-3-20 21:28:44 org.apache.catalina.startup.Catalina start

信息: Server startup in 2481 ms

 

 

  • 鼠标左键单击eclipse工具栏中的“Stop Tomcat”图标按钮,停止Tomcat的运行。

 

7.4、配置eclipse针对tomcat Server的运行环境,选择菜单

菜单路径:Window > Preferences



 


 

7.5、设置eclipse字段集编码,选择菜单

菜单路径:Window > Preferences

7.5.1、设置workspace的字符集编码


7.5.2、设置jsp文件的字符集编码


8.、创建一个简单的web project

8.1、新建一个web工程

菜单路径:File > New > Dynamic Web Project


可以看到以下结果:


 

8.2、设置项目的tomcat的配置信息

点击Project  Explorer中的项目根结点后,选择菜单

菜单路径:Project > Properties


查看C:\j2ee\Tomcat 6.0\conf\server.xml文件,可以看到有以下一段信息:

<?xml version='1.0' encoding='utf-8'?>

<!--

  Licensed to the Apache Software Foundation (ASF) under one or more

  contributor license agreements.  See the NOTICE file distributed with

  this work for additional information regarding copyright ownership.

  The ASF licenses this file to You under the Apache License, Version 2.0

  (the "License"); you may not use this file except in compliance with

  the License.  You may obtain a copy of the License at

 

      http://www.apache.org/licenses/LICENSE-2.0

 

  Unless required by applicable law or agreed to in writing, software

  distributed under the License is distributed on an "AS IS" BASIS,

  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  See the License for the specific language governing permissions and

  limitations under the License.

-->

<!-- Note:  A "Server" is not itself a "Container", so you may not

     define subcomponents such as "Valves" at this level.

     Documentation at /docs/config/server.html

 -->

<Server port="8005" shutdown="SHUTDOWN">

 

  <!--APR library loader. Documentation at /docs/apr.html -->

  <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />

  <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->

  <Listener className="org.apache.catalina.core.JasperListener" />

  <!-- Prevent memory leaks due to use of particular java/javax APIs-->

  <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />

  <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->

  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />

  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

 

  <!-- Global JNDI resources

       Documentation at /docs/jndi-resources-howto.html

  -->

  <GlobalNamingResources>

    <!-- Editable user database that can also be used by

         UserDatabaseRealm to authenticate users

    -->

    <Resource name="UserDatabase" auth="Container"

              type="org.apache.catalina.UserDatabase"

              description="User database that can be updated and saved"

              factory="org.apache.catalina.users.MemoryUserDatabaseFactory"

              pathname="conf/tomcat-users.xml" />

  </GlobalNamingResources>

 

  <!-- A "Service" is a collection of one or more "Connectors" that share

       a single "Container" Note:  A "Service" is not itself a "Container",

       so you may not define subcomponents such as "Valves" at this level.

       Documentation at /docs/config/service.html

   -->

  <Service name="Catalina">

 

    <!--The connectors can use a shared executor, you can define one or more named thread pools-->

    <!--

    <Executor name="tomcatThreadPool" namePrefix="catalina-exec-"

        maxThreads="150" minSpareThreads="4"/>

    -->

 

 

    <!-- A "Connector" represents an endpoint by which requests are received

         and responses are returned. Documentation at :

         Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)

         Java AJP  Connector: /docs/config/ajp.html

         APR (HTTP/AJP) Connector: /docs/apr.html

         Define a non-SSL HTTP/1.1 Connector on port 8080

    -->

    <Connector port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    <!-- A "Connector" using the shared thread pool-->

    <!--

    <Connector executor="tomcatThreadPool"

               port="8080" protocol="HTTP/1.1"

               connectionTimeout="20000"

               redirectPort="8443" />

    -->          

    <!-- Define a SSL HTTP/1.1 Connector on port 8443

         This connector uses the JSSE configuration, when using APR, the

         connector should be using the OpenSSL style configuration

         described in the APR documentation -->

    <!--

    <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"

               maxThreads="150" scheme="https" secure="true"

               clientAuth="false" sslProtocol="TLS" />

    -->

 

    <!-- Define an AJP 1.3 Connector on port 8009 -->

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

 

 

    <!-- An Engine represents the entry point (within Catalina) that processes

         every request.  The Engine implementation for Tomcat stand alone

         analyzes the HTTP headers included with the request, and passes them

         on to the appropriate Host (virtual host).

         Documentation at /docs/config/engine.html -->

 

    <!-- You should set jvmRoute to support load-balancing via AJP ie :

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">        

    -->

    <Engine name="Catalina" defaultHost="localhost">

 

      <!--For clustering, please take a look at documentation at:

          /docs/cluster-howto.html  (simple how to)

          /docs/config/cluster.html (reference documentation) -->

      <!--

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

      -->       

 

      <!-- The request dumper valve dumps useful debugging information about

           the request and response data received and sent by Tomcat.

           Documentation at: /docs/config/valve.html -->

      <!--

      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>

      -->

 

      <!-- This Realm uses the UserDatabase configured in the global JNDI

           resources under the key "UserDatabase".  Any edits

           that are performed against this UserDatabase are immediately

           available for use by the Realm.  -->

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"

             resourceName="UserDatabase"/>

 

      <!-- Define the default virtual host

           Note: XML Schema validation will not work with Xerces 2.2.

       -->

      <Host name="localhost"  appBase="webapps"

            unpackWARs="true" autoDeploy="true"

            xmlValidation="false" xmlNamespaceAware="false">

 

        <!-- SingleSignOn valve, share authentication between web applications

             Documentation at: /docs/config/valve.html -->

        <!--

        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />

        -->

 

        <!-- Access log processes all example.

             Documentation at: /docs/config/valve.html -->

        <!--

        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 

               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>

        -->

 

<Context path="" reloadable="true" docBase="C:\workspace\MyWebApp\WebContent" workDir="C:\workspace\MyWebApp\work" />

 

      </Host>

    </Engine>

  </Service>

</Server>

 

 

8.3、创建项目的默认页面default.jsp

 

点击工程下WebContent文件夹,右击鼠标后,选择菜单New > JSP File
 


 

显示画面如下:

 


输入文件名default.jsp后,点击Finish按钮,编辑default.jsp

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

 Hello, this is my first web application!

</body>

</html>

 

 

8.4、在eclipse中启动tomcat

 

8.5、在浏览器中输入地址http://localhost:8080

 

可以看到以下结果:


  • 大小: 42.9 KB
  • 大小: 52.3 KB
  • 大小: 39.5 KB
  • 大小: 95.9 KB
  • 大小: 86.1 KB
  • 大小: 120.1 KB
  • 大小: 74.2 KB
  • 大小: 68.8 KB
  • 大小: 50.9 KB
  • 大小: 113.7 KB
  • 大小: 81.7 KB
  • 大小: 81.7 KB
  • 大小: 105.3 KB
  • 大小: 101 KB
  • 大小: 99.6 KB
  • 大小: 121.3 KB
  • 大小: 52.6 KB
  • 大小: 79.4 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics