使用eclipse写第一个Java

您所在的位置:网站首页 怎么用eclipse写javaweb 使用eclipse写第一个Java

使用eclipse写第一个Java

2023-04-12 04:01| 来源: 网络整理| 查看: 265

1、先创建一个Java_web项目

 

 

 

 

 如果你没有下载过Tomcat服务器,不会配置,建议看一下我得这一篇博客:https://www.cnblogs.com/kongbursi-2292702937/p/11746773.html

我得项目名称为day02

上面信息填完之后点next,别点finish

 

 

 

再点next

 

 

 

 

 

 

 

 之后finish就可以,创建完之后如下:

 

 

 

之后创建一个Java类hello_world.java,继承于GenericServlet

 

 

 

文件内容如下:

import java.io.IOException; import javax.servlet.GenericServlet; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class hello_world extends GenericServlet { @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { // TODO Auto-generated method stub res.getOutputStream().write("hello_world".getBytes()); } }

之后配置web.xml文件,以使得外界可以访问到这个文件

 

 

 

这里给出文件内容:不需要全部一样,只要web.xml文件红色框内一样就可以

day02 index.html index.htm index.jsp default.html default.htm default.jsp hello_world day02.hello_world hello_world /hello_world

 

之后创建一个Tomcat服务器

 

 

 

点了之后默认就运行了。可以右键点击停止或启动:

 

 

 

启动Tomcat服务器之后,打开网页访问127.0.0.1:8080/day02/hello_world

 

day02就是:

 

 

 

hello_world就是:

 

最后记得要把day02发布到服务器上面

 

 

 

 

 

完结!!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3