servlet从xml提取数据登陆
在xml文档下可以设置参数的初始值,在这里把他当成了数据库在用
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>InitParamServlet</servlet-name>
<servlet-class>servlet.InitParamServlet</servlet-class>
<init-param>
<param-name>helloween</param-name>
<param-value>password</param-value>
</init-param>
<init-param>
<param-name>admin</param-name>
<param-value>admin</param-value>
</init-param>
<init-param>
<param-name>babyface</param-name>
<param-value>babyface</param-value>
</init-param>
</servlet>
变量名为账号,值为密码
在doGet中的<form>提供的<input type='text' name='username'...>的值
可以传递到doPost
然后用String username=request.getParameter("username");来获取他
再和xml里面的变量比较


原码
package servlet; import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class InitParamServlet extends HttpServlet { /**
* Constructor of the object.
*/
public InitParamServlet() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.println("<form action='"+request.getRequestURI()+"' method='post'>");
out.println("账号:<input type='text' name='username'<br><br/>");
out.println("密码:<input type='password' name='password'<br><br/>");
out.println("<input type='submit' value=' 登陆 '>");
out.println("</form>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8"); response.setContentType("text/html");
PrintWriter out = response.getWriter();
String username=request.getParameter("username");
String password=request.getParameter("password");
Enumeration params=this.getInitParameterNames();
for(;params.hasMoreElements();){
String usernameParam=params.nextElement().toString();
String passnameParam=getInitParameter(usernameParam);
if(usernameParam.equalsIgnoreCase(username)&&passnameParam.equals(password)){
request.getRequestDispatcher("/WEB-INF/notice.html").forward(request,response);
return;
}
}
doGet(request,response);//不匹配的话重新加载
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
} }
servlet从xml提取数据登陆的更多相关文章
- 用servlet来提取数据,并作统计,然后用jfreechart画图
指定时间范围的数据提取,并做统计: 用servlet来提取数据,并作统计,然后用jfreechart画图. 使用的话,需要在web.xml里面配置相应的servlet,并且在index.jsp页面做引 ...
- 提取数据表保存为XML文件
//连接数据库 SqlConnection con = new SqlConnection("server=****;database=****;uid=sa;pwd=********&qu ...
- jsp+servlet+mysql简单实现用户登陆注册
原码,项目中遇到的错误,解决方法,文章最后有链接可以获取 项目简介 *有的网友说在修改和删除时会触发error,建议各位不要去把用户名命名为中文! 功能描述 登陆,注册,用户一览表,修改,删除,添加, ...
- JSP Servlet SQL 三者之间数据传递
前言: 最近一直在做WEB开发,现总结一下这一段时间的体会和感触. 切记,web开发重点在于前台数据交互,页面美化而不要太沉溺于底层数据. 浏览器时代来到,向我们召唤出更炫.更简洁.更方便.更大气的网 ...
- 关于iOS中几种第三方对XML/JSON数据解析的使用
Json XML 大数据时代,我们需要从网络中获取海量的新鲜的各种信息,就不免要跟着两个家伙打交道,这是两种结构化的数据交换格式.一般来讲,我们会从网络获取XML或者Json格式的数据,这些数据有着特 ...
- scrapy框架Selector提取数据
从页面中提取数据的核心技术是HTTP文本解析,在python中常用的模块处理: BeautifulSoup 非常流行的解析库,API简单,但解析的速度慢. lxml 是一套使用c语言编写的xml解析 ...
- Ajax获取 Json文件提取数据
摘自 Ajax获取 Json文件提取数据 1. json文件内容(item.json) [ { "name":"张国立", "sex":&q ...
- JMETER从JSON响应中提取数据
如果你在这里,可能是因为你需要使用JMeter从Json响应中提取变量. 好消息!您正在掌握掌握JMeter Json Extractor的权威指南.作为Rest API测试指南的补充,您将学习掌握J ...
- 如何使用JMETER从JSON响应中提取数据
如果你在这里,可能是因为你需要使用JMeter从Json响应中提取变量. 好消息!您正在掌握掌握JMeter Json Extractor的权威指南.作为Rest API测试指南的补充,您将学习掌握J ...
随机推荐
- Java 语言中 Enum 类型的使用介绍
Enum 类型的介绍 枚举类型(Enumerated Type) 很早就出现在编程语言中,它被用来将一组类似的值包含到一种类型当中.而这种枚举类型的名称则会被定义成独一无二的类型描述符,在这一点上和常 ...
- lambda -- Filter Java Stream to 1 and only 1 element
up vote10down votefavorite I am trying to use Java 8 Streams to find elements in a LinkedList. I wan ...
- Linux Shell编程(29)——函数
和"真正的"编程语言一样, Bash也有函数,虽然在某些实现方面稍有些限制. 一个函数是一个子程序,用于实现一串操作的代码块,它是完成特定任务的"黑盒子". 当 ...
- Linux学习笔记16——wait函数
wait函数的定义如下: #include <sys/types.h> #include <sys/wait.h> pid_t wait(int *stat_loc); wai ...
- simulink下直接代码生成
连接好DSP,打开Matlab,首先必须要更改环境,要不不能编译通过 输入C2000lib,打开库, 在C2833X DSP Chip Support中添加外设,然后在C2000 Target Pre ...
- ACM1230_火星A+B(进位的运算)
//只要看懂火星A+B的进位关系就好了 #include<stdio.h> ]={,,,,,,,,,,,,,,,,,,,,,,,,,}; int main() { ],b[],sum[]; ...
- Building Apps with Over 65K Methods(解决APP引用方法总数超过65536)
本文翻译自http://developer.android.com/intl/zh-cn/tools/building/multidex.html#about.主要介绍当我们Android App中函 ...
- 《University Calculus》-chape6-定积分的应用-平面曲线长度
平面曲线的长度: 积分的重要作用体现在处理曲线和曲面. 在这里我们讨论平面中一条用参数形式表达的曲线:x=f(t),y=g(t),a≤t≤b. 如图. y=f(x)形式的弧长计算: 之前我们讨论过平面 ...
- Ural 1332 把圆细分+圆内切,内含关系判定
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1332 #include<cstdio> #include<cstrin ...
- Web服务器性能/压力测试工具http_load、webbench、ab、Siege使用教程 - VPS侦探
Web服务器性能/压力测试工具http_load.webbench.ab.Siege使用教程 - VPS侦探 http://soft.vpser.net/test/http_load/http_loa ...