action="post" 、 servletconfig 、 servletcontext 、getPrintWiter() 、context-param、 init-param(第一个完整的servlet)
<!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)的更多相关文章
- Servlet开发(三)之ServletConfig,ServletContext
1. ServletConfig Servlet是开发动态web的技术,而web.xml是Tomcat工程中最基础也最重要的配置文件,Tomcat启动项目的时候会加载并读取这个文件,其中web.xml ...
- 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 ...
- 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 ...
- Server,Servlet,ServletConfig,ServletContext,Session,Request,Response
Server流程 解析URL->找到应用->找到Servlet->实例化Servlet->调用init->调用service->返回响应->调用destroy ...
- raise PDFEncryptionError('Unknown algorithm: param=%r' % param) pdfminer.pdfdocument.PDFEncryptionError: Unknown algorithm
使用pdfminer遇到的pdf文件加密问题: raise PDFEncryptionError('Unknown algorithm: param=%r' % param) pdfminer.pdf ...
- 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. ...
- JavaWeb -- 服务器传递给Servlet的对象 -- ServletConfig, ServletContext,Request, Response
1. ServletConfig 有一些东西不合适在程序中写死,应该写在web.xml中,比如 文字怎么显示, 访问数据库名 和 密码, servlet要读取的配置文件 等等.. l在Servle ...
- servlet ServletConfig ServletContext
ServletConfig对象 在Servlet的配置文件中,可以使用一个或者多个<init-param>标签为servlet配置一些初始化参数. 当servlet配置了初始化参数后,we ...
- 第一个web程序(web.xml , ServletConfig , ServletContext)
一:第一个jsp程序 1.项目设计结构 2.新建Person.java package com.java.demo; public class Person { public void printSt ...
随机推荐
- Python字符串(Python学习笔记02)
字符串 Python 3 中的字符串可以使用双引号或单引号标示,如果字符串出现引号,则可以使用 \ 来去除引号标示字符串的作用. 几种字符串的表示方法: str1 = "hello" ...
- 解决ASP.NET Core部署到IIS,更新项目"另一个程序正在使用此文件,进程无法访问"
问题:部署到IIS上的ASP.NET Core项目,在更新的时候会进程占用的错误 初步解决方案: 1,关闭应用程序池 2,关闭网站 3,更新项目 缺点:网站没法访问,部署项目停的时间过长 查询官方文档 ...
- Springboot源码分析
参考资料 https://www.cnblogs.com/lizongshen/p/9127999.html
- 【Codeforces 1019A】Elections
[链接] 我是链接,点我呀:) [题意] 每个人都有自己喜欢的队员 但是如果贿赂他们可以让他们更改自己喜欢的队员 问你最少要花多少钱贿赂队员才能让1号队员严格有最多的人喜欢? [题解] 除了1号之外, ...
- 戏说云计算之PaaS,IaaS,SaaS
最近我们聊到"CRM系统PAAS化",有些可能就不了解,到底什么是PAAS.云计算还有IaaS,SaaS概念,这三者之间有什么区别?今天智云通CRM系统小编用通俗易懂的例子跟大家分 ...
- RCC 2014 Warmup (Div. 2) 蛋疼解题总结
A. Elimination time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Uva12657 Boxes in a Line
题目链接:传送门 分析:每次操作都会花费大量时间,显然我们只需要关注每个元素的左边是啥,右边是啥就够了,那么用双向链表,l[i]表示i左边的数,r[i]表示i右边的数,每次操作模拟一下数组的变化就好了 ...
- 【整理】uclibc,eglibc,glibc之间的区别和联系
http://www.crifan.com/relation_between_uclibc_glibc_eglibc/ 1.Glibc glibc = GNU C Library 是GNU项(GNU ...
- 安装elasticsearch遇到的签名和目标被配置多次的问题
命中:6 http://ppa.launchpad.net/ondrej/php/ubuntu bionic InRelease获取:7 http://packages.elastic.co/elas ...
- Ubuntu-14.04. sh .py腳本双击無法執行问题的解决方法
Ubuntu-14.04中默认文件用gedit文本打开,而不是BT5里面的默认双击打开四个选择,例如以下图(这是配置完毕后的结果,就不换BT5系统了): 直接文本打开,尽管非常安全.实际生产中肯定是不 ...