<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>注册</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="post" action="/ServletOne/registered.do">
<table width="400px" height="300px">
<tr>
<td align="right">用户名:</td>
<td><input type="text" name="username"/></td>
<tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="passwd"/></td>
<tr> <tr>
<td colspan="2" align="center"><input type="submit" value="注册"/></td>
</tr>
</table>
</form> </body>
</html>
package registered;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration; import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class RegisteredServlet extends HttpServlet { public void init() throws ServletException {
ServletConfig scf=this.getServletConfig();
ServletContext sct=this.getServletContext();
//获取init配置参数指定参数 config jack
System.out.println("config "+scf.getInitParameter("name"));
//获取整个init配置参数数组 Enumeration name Enumeration age
Enumeration e=scf.getInitParameterNames();
while(e.hasMoreElements()){
System.out.println("Enumeration "+e.nextElement().toString());
}
//获取context-param参数值 context ServletContextValue
System.out.println("context "+sct.getInitParameter("ServletContextName"));
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("DoGet()");
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("DoPost()");
String name=request.getParameter("username");
String passwd=request.getParameter("passwd");
PrintWriter out=response.getWriter();
out.write("username="+name);
out.write("<br/>");
out.write("passwd="+passwd);
}
}
<?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/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>ServletOne</display-name>
<context-param>
<param-name>ServletContextName</param-name>
<param-value>ServletContextValue</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<!--配置时一律小写 -->
<servlet>
<servlet-name>Servlet01</servlet-name>
<servlet-class>servlet_1121.Servlet01</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet01</servlet-name>
<url-pattern>/s1</url-pattern>
</servlet-mapping>
<!-- 注册 -->
<servlet>
<servlet-name>RegisteredServlet</servlet-name>
<servlet-class>registered.RegisteredServlet</servlet-class>
<init-param>
<param-name>name</param-name>
<param-value>jack</param-value>
</init-param>
<init-param>
<param-name>age</param-name>
<param-value>20</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>RegisteredServlet</servlet-name>
<url-pattern>/registered.do</url-pattern>
</servlet-mapping>
</web-app>

action="post" 、 servletconfig 、 servletcontext 、getPrintWiter() 、context-param、 init-param(第一个完整的servlet)的更多相关文章

  1. Servlet开发(三)之ServletConfig,ServletContext

    1. ServletConfig Servlet是开发动态web的技术,而web.xml是Tomcat工程中最基础也最重要的配置文件,Tomcat启动项目的时候会加载并读取这个文件,其中web.xml ...

  2. struts 2.5 There is no Action mapped for namespace [/] and action name [user_find] associated with context path [/struts2_crm].

    遇到了这个错误. There is no Action mapped for namespace [/] and action name [user_find] associated with con ...

  3. struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []

    使用struts的都知道,下面使用通配符定义的方式很常见,并且使用也很方便: <action name="Crud_*" class="example.Crud&q ...

  4. Server,Servlet,ServletConfig,ServletContext,Session,Request,Response

    Server流程 解析URL->找到应用->找到Servlet->实例化Servlet->调用init->调用service->返回响应->调用destroy ...

  5. raise PDFEncryptionError('Unknown algorithm: param=%r' % param) pdfminer.pdfdocument.PDFEncryptionError: Unknown algorithm

    使用pdfminer遇到的pdf文件加密问题: raise PDFEncryptionError('Unknown algorithm: param=%r' % param) pdfminer.pdf ...

  6. SpringBoot项目 org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Jetty servlet container报错

    SpringBoot项目启动报错 ERROR 2172 --- [ main] o.s.boot.SpringApplication : Application startup failed org. ...

  7. JavaWeb -- 服务器传递给Servlet的对象 -- ServletConfig, ServletContext,Request, Response

    1.  ServletConfig  有一些东西不合适在程序中写死,应该写在web.xml中,比如 文字怎么显示, 访问数据库名 和 密码, servlet要读取的配置文件 等等.. l在Servle ...

  8. servlet ServletConfig ServletContext

    ServletConfig对象 在Servlet的配置文件中,可以使用一个或者多个<init-param>标签为servlet配置一些初始化参数. 当servlet配置了初始化参数后,we ...

  9. 第一个web程序(web.xml , ServletConfig , ServletContext)

    一:第一个jsp程序 1.项目设计结构 2.新建Person.java package com.java.demo; public class Person { public void printSt ...

随机推荐

  1. CTSC2018 Day2T1 Juice混合果汁

    [题解] 在考场上A掉的题. 把美味度排个序,然后按照价格p为权值建立主席树,把每个果汁按照拍好的顺序添加进去.主席树上维护总升数cnt以及总价格sum.对于每个询问,我们二分一个美味值,check的 ...

  2. 完美解决在Servlet中出现一个输出中文乱码的问题

    @Override public void doPost(HttpServletRequest reqeust, HttpServletResponse response) throws Servle ...

  3. 消息传递(cogs 1001)

    问题描述WZland开办了一个俱乐部(这里面可以干任何的事情),这引来了许多的人来加入.俱乐部的人数越来越多,关系也越来越复杂……俱乐部的人来自各个地方,为了增加友谊,俱乐部举行了一次晚会.晚会上又进 ...

  4. 洛谷—— P1122 最大子树和

    https://www.luogu.org/problem/show?pid=1122 题目描述 小明对数学饱有兴趣,并且是个勤奋好学的学生,总是在课后留在教室向老师请教一些问题.一天他早晨骑车去上课 ...

  5. Snail—UI学习之自己定义通知NSNotification

    背景是:一个界面跳转到第二个界面 然后 第一个界面发了一个通知  然后第二个界面收到这个通知后 把里面的数据取出来 在RootViewController.m中写入以下代码 #import " ...

  6. Linux内核之于红黑树and AVL树

    为什么Linux早先使用AVL树而后来倾向于红黑树?       实际上这是由红黑树的有用主义特质导致的结果,本短文依旧是形而上的观点.红黑树能够直接由2-3树导出.我们能够不再提红黑树,而仅仅提2- ...

  7. easyui 后台框架搭建

    近期公司要搭建一个后台管理项目.因为美工缺少 选择使用easyui jquery 框架 仅仅要懂点html js 这个用起来不是难事,看过API.在网上看了些 将它们组装起来 进行改动.因为本人也是第 ...

  8. C 基础 全局变量

    /** 被static修饰的局部变量 1.只有一份内存, 只会初始化一次 2.生命周期会持续到程序结束 3.static改变了局部变量的生命周期, 但是不能改变局部变量的作用域 被static修饰的全 ...

  9. 《iOS Human Interface Guidelines》——Wallet

    Wallet Wallet(钱包)帮助人们查看和管理Pass(凭证),这是一种相似于登机牌.优惠券.会员卡.奖励卡和各种票的物理凭证的数字替代.Wallet也同意人们加入信用卡.借记卡和储值卡来和Ap ...

  10. 在VM中安装Android4.4连接小米手机 之 安装小米手环APP

    1.下载APP 在能够上网的情况的,搜索 小米手环APP就能够找到下载地址 2.安装APP 进入终端 3.在终端按下图红色区域语句依次输入. 先进入超级用户 找到下载的APP所在的路径 然后进入该路径 ...