千家信息网

在MyEclipse 6.5下怎么使用jetty

发表于:2025-02-06 作者:千家信息网编辑
千家信息网最后更新 2025年02月06日,本篇内容介绍了"在MyEclipse 6.5下怎么使用jetty"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够
千家信息网最后更新 2025年02月06日在MyEclipse 6.5下怎么使用jetty

本篇内容介绍了"在MyEclipse 6.5下怎么使用jetty"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

在MyEclipse 6.5下使用jetty的全过程。

环境:Windows XP + JDK 1.6.11 + MyEclipse 6.5 + jetty-7.0.0pre3

1. 打开myEclipse, 新建java工程Jetty,建立webapps和 logs文件夹(和src同级),在src下建立config、servlet及test文件夹,在webapps建立manage目录作为web工作目录。

2. 将${ROOT}\jetty-7.0.0pre3\lib下的三个jar包加入工程的classpath,将${Root}:\jetty-7.0.0pre3\lib\jsp-2.1下的四个jar包加入工程的classpath,copy ${ROOT}\jetty-7.0.0pre3\etc下的jetty.xml, webdefault.xml和realm.properties到src\config下,同时copy ${ROOT}\jetty-7.0.0pre3\contexts下的test.xml到src\config下并改名为manage.xml。

3. 修改jetty.xml, manage.xml,将这些配置文件中带有jetty.xml、webdefault.xml及realm.properties的路径改为src\config,并在webapps/manage下新建index.jsp。

4. 在test目录下新建Start.java,代码如下:

1 import org.mortbay.jetty.*;2 3 import java.io.*;4 5 import org.mortbay.jetty.handler.*;6 7 import org.mortbay.xml.*;8 9 public class start {10 11 public static void main(String args[]) {12 13 Server server = new Server(8080);14 15 server.setHandler(new DefaultHandler());16 17 XmlConfiguration cfg = null;18 19 try {20 21 cfg = new XmlConfiguration(new FileInputStream("./src/com/greysh/config/jetty.xml"));22 23 cfg.configure(server);24 25 server.start();26 27 System.out.println("Jetty Started ...");28 29 } catch (FileNotFoundException e) {30 31 e.printStackTrace();32 33 }34 35 catch (IOException e) {36 37 e.printStackTrace();38 39 } catch (Exception e) {40 41 e.printStackTrace();42 43 }44 45 }46 47 }

运行Start类,用IE访问http://localhost:8080/, 点击/manage ---> org.mortbay.jetty.webapp.WebAppContext@1275d39{/manage,file:/D:/Program%20Files/MyEclipse%206.5/workspace/Jetty/webapps/manage/} ,此时Jetty就可以成功运行了。

如果要在Jetty中运行servlet,操作过程如下:

1. 在webapps/manage下建立WEB-INF, 并新建web.xml用于配置servlet, 同时将contexts下的webdefalut.xml的内容copy到web.xml里。

2. 修改contexts下的manage.xml,在webapps目录下写jsp程序,并在servlet目录下写相应的servlet处理程序,同时在web.xml里进行配置。

3. 运行Start类,用IE访问http://localhost:8080/, 点击/manage ---> org.mortbay.jetty.webapp.WebAppContext@bb05de

到此Jetty运行servlet成功

"在MyEclipse 6.5下怎么使用jetty"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0