servlet(java)第一个应用
来源:互联网 发布:php网站技术架构图 编辑:程序博客网 时间:2024/06/06 00:03
web.xml
/////
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this 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 agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
<display-name>Tomcat Host Manager Application</display-name>
<description>
A scriptable host management web application for the Tomcat Web Server;
Manager lets you view, create and remove virtual hosts.
</description>
<servlet>
<servlet-name>helloworld</servlet-name>
<servlet-class>com.kuenking.helloworld</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
</servlet>
<!-- Define the Manager Servlet Mapping -->
<servlet-mapping>
<servlet-name>helloworld</servlet-name>
<url-pattern>/text</url-pattern>
</servlet-mapping>
</web-app>
///class文件夹中的 helloworld.java
///这个是第一个Servlet
package com.kuenking;
import javax.servlet.*;
import java.io.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
public class helloworld implements Servlet{
/**
* Method init
*
*Servlet初始化;该函数只被调用一次啊!
* @param parm1
*
@throws ServletException
*
*/
public void init(ServletConfig parm1) throws ServletException {
// TODO: Add your code here
System.out.println("Init it");
}
/**
* Method getServletConfig
*
*
* @return
*
*/
public ServletConfig getServletConfig() {
// TODO: Add your code here
return null;
}
/**
* Method service
*
*
* @param parm1
* @param parm2
*这个函数应用于处理业务逻辑 程序员应当把业务逻辑代码写在这里
*当用户每次访问该Servlet时候,都会调用一次
*req:用于获得客户端的信息;
*res:应于向客户端返回信息;
@throws ServletException
@throws IOException
*
*/
public void service(ServletRequest parm1, ServletResponse parm2) throws ServletException, IOException {
// TODO: Add your code here
System.out.println("service it");
///首先从RES中得到printwriter
PrintWriter pw = parm2.getWriter();
pw.println("hello world!");
}
/**
* Method getServletInfo
*
*
* @return
*
*/
public String getServletInfo() {
// TODO: Add your code here
return "";
}
/**
* Method destroy
*
*销毁Servlet示例;(释放内存)
*reload该servlet 或者关机tomcat两个都会释放内存!
*/
public void destroy() {
// TODO: Add your code here
System.out.println("destroy!");
}
}
///打开Tomcat ,,最小化 不要关机!!!
在浏览器中输入:http://127.0.0.1:8080/myWebSite/text (Text 是servlet中的url-pattern)httpServlet需要reload tomcat
- servlet(java)第一个应用
- 第一个Servlet应用
- 第一个Java应用
- Java Servlet之编写第一个Servlet
- java笔记——第一个servlet重点理解web应用和servlet
- 10.24 第一个JAVA应用
- java web第一个servlet配置过程
- Java Servlet和JSP教程:三、第一个Servlet
- Servlet(一)第一个Servlet
- 三、第一个Servlet
- 第一个Servlet
- 编写第一个servlet
- 三、第一个Servlet
- 第一个Servlet不容易
- 第一个servlet程序
- 第一个servlet程序
- 第一个Servlet程序
- 第一个Servlet程序
- CI在nginx环境下去掉url中的index.php
- 使用JMeter做压力测试
- js
- 2014华为校园招聘机试——字符串过滤
- 电子传真智能分发功能的实现
- servlet(java)第一个应用
- android 屏幕密度相关知识汇总
- TOJ 3502: Triangle (pick定理)
- Spring MVC增强型Controller-MultiActionController 使用方法
- Semantic Hashing
- linux下oracle自启
- line 1: syntax error: word unexpected (expecting ")")
- Go语言学习四:struct类型
- Fedora 添加国内源(sohu, 163)