设为首页 收藏本站
查看: 728|回复: 0

[经验分享] web应用开发入门(1)-使用eclipse搭建tomcat下web应用项目详细步骤

[复制链接]

尚未签到

发表于 2017-2-7 11:45:49 | 显示全部楼层 |阅读模式

以下是对第一次学习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。
 
DSC0000.png
 点击Next按钮


DSC0001.png
 点击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

DSC0002.png

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

DSC0003.png

 
7.3、配置tomcat可以在eclipse中启用停用的选项
菜单路径:Window > Preferences

DSC0004.png


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

DSC0005.png

eclipse的控制台中显示的信息如下:
2012-3-20 21:28:41org.apache.catalina.core.AprLifecycleListener init
信息: The APR based Apache Tomcat Native library whichallows optimal performance in production environments was not found on thejava.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:\ProgramFiles (x86)\Windows7Master;C:\Program Files (x86)\Lenovo\AccessConnections\;C:\PROGRA~2\IBM\SQLLIB\BIN;C:\PROGRA~2\IBM\SQLLIB\FUNCTION;C:\PROGRA~2\IBM\SQLLIB\SAMPLES\REPL;.
2012-3-20 21:28:42org.apache.coyote.http11.Http11Protocol init
信息: Initializing Coyote HTTP/1.1 on http-8080
2012-3-20 21:28:42org.apache.catalina.startup.Catalina load
信息: Initialization processed in 1959 ms
2012-3-20 21:28:42org.apache.catalina.core.StandardService start
信息: Starting service Catalina
2012-3-20 21:28:42org.apache.catalina.core.StandardEngine start
信息: Starting Servlet Engine: Apache Tomcat/6.0.35
2012-3-20 21:28:42org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptorhost-manager.xml
2012-3-20 21:28:43org.apache.catalina.startup.HostConfig deployDescriptor
信息: Deploying configuration descriptor manager.xml
2012-3-20 21:28:43org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory docs
2012-3-20 21:28:43org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory examples
2012-3-20 21:28:44org.apache.catalina.core.ApplicationContext log
信息: ContextListener: contextInitialized()
2012-3-20 21:28:44org.apache.catalina.core.ApplicationContext log
信息: SessionListener: contextInitialized()
2012-3-20 21:28:44org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory ROOT
2012-3-20 21:28:44org.apache.coyote.http11.Http11Protocol start
信息: Starting Coyote HTTP/1.1 on http-8080
2012-3-20 21:28:44 org.apache.jk.common.ChannelSocketinit
信息: 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:44org.apache.catalina.startup.Catalina start
信息: Server startup in 2481 ms

  • 鼠标左键单击eclipse工具栏中的“Stop Tomcat”图标按钮,停止Tomcat的运行。
 
7.4、配置eclipse针对tomcat Server的运行环境,选择菜单
菜单路径:Window > Preferences

DSC0006.png

  
DSC0007.png
  
DSC0008.png
 7.5、设置eclipse字段集编码,选择菜单
菜单路径:Window > Preferences
7.5.1、设置workspace的字符集编码

DSC0009.png

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

DSC00010.png

8.、创建一个简单的webproject
8.1、新建一个web工程
菜单路径:File > New > Dynamic Web Project

DSC00011.png

可以看到以下结果:

DSC00012.png

 
8.2、设置项目的tomcat的配置信息
点击Project  Explorer中的项目根结点后,选择菜单
菜单路径:Project > Properties

DSC00013.png

查看C:\j2ee\Tomcat 6.0\conf\server.xml文件,可以看到有以下一段信息:
<?xmlversion='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 informationregarding copyright ownership.
  The ASF licenses this file to You under theApache License, Version 2.0
  (the "License"); you may not usethis 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 agreedto in writing, software
  distributed under the License is distributedon an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,either express or implied.
  See the License for the specific languagegoverning permissions and
  limitations under the License.
-->
<!--Note:  A "Server" is not itselfa "Container", so you may not
     define subcomponents such as"Valves" at this level.
     Documentation at /docs/config/server.html
 -->
<Serverport="8005" shutdown="SHUTDOWN">
 
  <!--APR library loader. Documentation at/docs/apr.html -->
  <ListenerclassName="org.apache.catalina.core.AprLifecycleListener"SSLEngine="on" />
  <!--Initialize Jasper prior to webapps areloaded. Documentation at /docs/jasper-howto.html -->
  <ListenerclassName="org.apache.catalina.core.JasperListener" />
  <!-- Prevent memory leaks due to use ofparticular java/javax APIs-->
  <ListenerclassName="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
  <!-- JMX Support for the Tomcat server.Documentation at /docs/non-existent.html -->
  <ListenerclassName="org.apache.catalina.mbeans.ServerLifecycleListener" />
  <ListenerclassName="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
 
  <!-- Global JNDI resources
       Documentation at/docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <!-- Editable user database that canalso be used by
         UserDatabaseRealm to authenticateusers
    -->
    <Resource name="UserDatabase"auth="Container"
             type="org.apache.catalina.UserDatabase"
              description="User databasethat can be updated and saved"
             factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
             pathname="conf/tomcat-users.xml" />
  </GlobalNamingResources>
 
  <!-- A "Service" is a collectionof one or more "Connectors" that share
       a single "Container"Note:  A "Service" is notitself a "Container",
       so you may not define subcomponents suchas "Valves" at this level.
       Documentation at/docs/config/service.html
   -->
  <Service name="Catalina">
 
    <!--The connectors can use a sharedexecutor, you can define one or more named thread pools-->
    <!--
    <Executorname="tomcatThreadPool" namePrefix="catalina-exec-"
        maxThreads="150"minSpareThreads="4"/>
    -->
 
 
    <!-- A "Connector" representsan 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 onport 8080
    -->
    <Connector port="8080"protocol="HTTP/1.1"
              connectionTimeout="20000"
               redirectPort="8443"/>
    <!-- A "Connector" using theshared thread pool-->
    <!--
    <Connectorexecutor="tomcatThreadPool"
               port="8080"protocol="HTTP/1.1"
              connectionTimeout="20000"
               redirectPort="8443"/>
    -->          
    <!-- Define a SSL HTTP/1.1 Connector onport 8443
         This connector uses the JSSEconfiguration, when using APR, the
         connector should be using the OpenSSLstyle 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 port8009 -->
    <Connector port="8009"protocol="AJP/1.3" redirectPort="8443" />
 
 
    <!-- An Engine represents the entrypoint (within Catalina) that processes
         every request.  The Engine implementation for Tomcat standalone
         analyzes the HTTP headers includedwith the request, and passes them
         on to the appropriate Host (virtualhost).
         Documentation at/docs/config/engine.html -->
 
    <!-- You should set jvmRoute to supportload-balancing via AJP ie :
    <Engine name="Catalina"defaultHost="localhost" jvmRoute="jvm1">        
    -->
    <Engine name="Catalina"defaultHost="localhost">
 
      <!--For clustering, please take a lookat documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (referencedocumentation) -->
      <!--
      <ClusterclassName="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->       
 
      <!-- The request dumper valve dumpsuseful debugging information about
           the request and response datareceived and sent by Tomcat.
           Documentation at:/docs/config/valve.html -->
      <!--
      <ValveclassName="org.apache.catalina.valves.RequestDumperValve"/>
      -->
 
      <!-- This Realm uses the UserDatabaseconfigured in the global JNDI
           resources under the key"UserDatabase".  Any edits
           that are performed against thisUserDatabase are immediately
           available for use by the Realm.  -->
      <RealmclassName="org.apache.catalina.realm.UserDatabaseRealm"
            resourceName="UserDatabase"/>
 
      <!-- Define the default virtual host
           Note: XML Schema validation will notwork with Xerces 2.2.
       -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true"autoDeploy="true"
            xmlValidation="false"xmlNamespaceAware="false">
 
        <!-- SingleSignOn valve, shareauthentication between web applications
             Documentation at:/docs/config/valve.html -->
        <!--
        <ValveclassName="org.apache.catalina.authenticator.SingleSignOn" />
        -->
 
        <!-- Access log processes allexample.
             Documentation at:/docs/config/valve.html -->
        <!--
        <ValveclassName="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
 

  
DSC00014.png
 显示画面如下:
 

DSC00015.png

输入文件名default.jsp后,点击Finish按钮,编辑default.jsp
 
<%@page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPEhtml PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<metahttp-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Inserttitle here</title>
</head>
<body>
 Hello, this is my first web application!
</body>
</html>
 
 
8.4、在eclipse中启动tomcat
 
8.5、在浏览器中输入地址http://localhost:8080
 
可以看到以下结果:

DSC00016.png

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-338809-1-1.html 上篇帖子: tomcat中conf\Catalina\localhost目录下的J2EE项目META-INF配置文件 下篇帖子: tomcat下面的jar包跟项目下面的jar包冲突
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表