Eclipse 第一个Servlet
来源:互联网 发布:js获取当前系统时间 编辑:程序博客网 时间:2024/06/05 10:12
Servlet:是一种托管在servlet容器里的web组件,可以动态生成内容,servlet容器负责servlet的生命周期,接受请求和响应请求。
项目目录如下:
MyServlet源代码
package cn.lemon;import java.io.IOException;import javax.servlet.GenericServlet;import javax.servlet.ServletException;import javax.servlet.ServletRequest;import javax.servlet.ServletResponse;import javax.servlet.annotation.WebServlet;public class MyServlet extends GenericServlet { public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { response.getOutputStream().write("Hello MyServlet!".getBytes()); }}
web.xml代码
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_9" version="2.4"> <servlet> <servlet-name>MyServlet</servlet-name> <!--定义的servlet应用名字 --> <servlet-class>cn.lemon.MyServlet</servlet-class> <!-- 具体的servlet文件 --> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <!-- 地址映射 --> <url-pattern>/s</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
注意:如果通过eclipse->new->servlet新建servlet不需要配置web.xml,会产生相应的注解。
如
@webservlet(urlpatterns={“/account”},
initparams={@webInitParam(name=”type”,value=”checking”)}
//初始化servelt参数,servletConfig.getInitParamter(“type”);
)
输入网址
工作过程:
1 http://localhost:8080/MyServlet/s
2 找到tomcat上的MyServlet项目下的 <url-pattern>/s</url-pattern>
配置
3 然后获取Servlet应用名 <servlet-name>MyServlet</servlet-name>
4 读取具体的类 <servlet-class>cn.lemon.MyServlet</servlet-class>
阅读全文
0 0
- Eclipse 第一个Servlet
- 用eclipse开发第一个Servlet
- eclipse开发第一个Servlet程序
- 在eclipse中调通你的第一个servlet
- 在Eclipse中建立第一个Servlet程序
- Eclipse下建立第一个Servlet程序步骤
- 第一个Servlet + Jsp(eclipse下实现)
- Servlet生命周期,工作原理,eclipse第一个Servlet,Servlet线程安全
- Servlet(一)第一个Servlet
- 三、第一个Servlet
- 第一个Servlet
- 编写第一个servlet
- 三、第一个Servlet
- 第一个Servlet不容易
- 第一个Servlet应用
- 第一个servlet程序
- 第一个servlet程序
- 第一个Servlet程序
- Kafka stream 开发碰到的问题:offset commit 失败 与 数据不准确
- 远程管理卡介绍&使用场景
- CSS Sprites样式生成工具的使用
- 总线基础--IIC总线
- module 'cv2' has no attribute 'CV_LOAD_IMAGE_GRAYSCALE'
- Eclipse 第一个Servlet
- 多线程的实现
- Python 中的类(上)
- CodeVS1025 选菜 解题报告【背包型DP】
- 代理及动态代理
- HDU-4899 Hero meet devil(DP套DP)
- mysql基本命令
- 希尔算法
- 记录一些开源软件