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 ...
随机推荐
- Android layer-list(1)
Android layer-list(1) Android layer-list,顾名思义,实现列表组合后形成的图层,写一个例子. activity_main.xml文件: <?xml v ...
- Vue插槽的另外一些特性
之前有个项目,想判断一下,某一个模板内的插槽是否被使用. 不知道是不是问题过于简单,网上没有这方面的说明.我就抽时间验证一下vue插槽相关的一些功能. 然后写下这篇随笔,希望对后来人能有一些帮助. 简 ...
- 用JQuery实现选中select里面的option显示对应的div
HTML: <select name="" onchange="select(this)"> <option value="1&q ...
- VS2017-NetCore项目整合Log4Net
1新建NetCore项目,我这里NetCoreSDK版本是2.2.0. 2.进入NuGet程序包官网 : https://www.nuget.org,搜索以下两个包并安装到项目中. Microsoft ...
- stl空间配置器alloc
new运算包含两阶段操作: 1) 调用::operator new分配内存 2) 调用构造函数构造对象内容 delete运算包含两阶段操作: 1)调用析构函数将对象析构 2)调用::op ...
- 1. 青蛙跳跳FrogJmp Count minimal number of jumps from position X to Y.
青蛙跳跳: package com.code; public class Test03_1 { public int solution(int X, int Y, int D) { int res = ...
- swift 2.0 语法 常量变量
import UIKit /*: 常量变量 * 常量: let * 变量: var 完整格式: * 修饰符(let/var) 常量/变量名称: 数据类型 */ let number: Int var ...
- [译]使用AssetBundle Manader
AssetBundle and the AssetBundle Manager 介绍 AssetBundle允许从本地或者远程服务器加载Assets资源,利用AssetBundles技术,Assets ...
- 500万url的es 批删除
bash 循环 算术计算 读写文件 [root@hadoop2 ~]# sh looh.sh1234LIZ1 2 3 4 0 1 2 3 4 5 6 7 8 9 10 0games:x:12:100 ...
- windowActionModeOverlay
windowActionModeOverlay: android:windowActionModeOverlay=“true|false” : actionmode 弹出时覆盖部分布局 若 ...