Servlet在web.xml中的配置
来源:互联网 发布:Mac pro 怎么看芒果TV 编辑:程序博客网 时间:2024/06/05 22:39
import javax.servlet.*;import java.io.IOException;import java.io.PipedWriter;import java.io.PrintWriter;/** * Created with IntelliJ IDEA. * User: wbb * Date: 14-6-17 * Time: 上午11:56 * To change this template use File | Settings | File Templates. */public class HelloWorldServlet implements Servlet { private ServletConfig config; @Override public void init(ServletConfig config) throws ServletException { this.config = config; } @Override public ServletConfig getServletConfig() { return config; } @Override public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException { PrintWriter out = servletResponse.getWriter(); out.println("Hello World"); out.close(); } @Override public String getServletInfo() { return null; //To change body of implemented methods use File | Settings | File Templates. } @Override public void destroy() { }}
web.xml的配置
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee<span style="white-space:pre"></span> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <!--用于声明Servlet--> <servlet> <!--指定Servlet的名字,在同一个Web应用程序中,每一个Servlet的名字必须是唯一的,该元素的内容不能为空--> <servlet-name>HelloWorldServlet</servlet-name> <!--指定Servlet的完整限定名(即该类所在的路径)--> <servlet-class>wbb.servlet.HelloWorld.HelloWorldServlet</servlet-class> <!--配置初始化参数--> <init-param> <param-name>greeting</param-name> <param-value>Welcome you</param-value> </init-param> </servlet> <!--用于在Servlet跟URL之间定义一个映射--> <servlet-mapping> <!--此处的Servlet名字必须跟<servlet>中的子元素<servlet-name>给的名字相同--> <servlet-name>HelloWorldServlet</servlet-name> <!--用于指定该Servlet的URL路径,该路径是相对Web应用程序上下文根的路径--> <url-pattern>/helloworld</url-pattern> </servlet-mapping>
在浏览器中输入:http://localhost:8080/helloworld即可,此处可以看出helloworld即为web.xml中定义的<url-pattern>
0 0
- servlet在web.xml中的配置
- Servlet在web.xml中的配置
- servlet在web.xml中的路径配置的映射
- Servlet和JSTL在web.xml中的配置
- “servlet监听器”以及在web.xml中的配置
- servlet中的web.xml的配置
- 优化Servlet在web.xml的配置
- 在web.xml中配置servlet定义
- Servlet在web.xml文件中的部署
- web.xml配置中的servlet及servlet-mapping
- Servlet-在web.xml中配置Servlet(Demo)
- web.xml配置Servlet
- servlet web.xml配置
- web.xml配置servlet
- web.xml 配置-servlet
- servlet中的web.xml
- Servlet中的web.xml
- Servlet中的web.xml
- 商城动态属性库搭建
- OCP-1Z0-051-题目解析-第10题
- Activity的四种launchMode
- 常用SQL
- UIModalPresentationFormSheet 改变加变大小
- Servlet在web.xml中的配置
- 如何在Struts的Action中直接使用POI生成Excel并下载
- Unity3D教程游戏开发鼠标路线
- Linux 下IPC总结(全)
- 分布式搜索elasticsearch java API 之(八)------使用More like this实现基于内容的推荐
- 【node】关于Most middleware (like session) is no longer bundled with Express and must be installed ……
- OCP-1Z0-051-题目解析-第11题
- button的长按事件
- unable to connect to your virtual device genymotion will now stop check your virtualbox network