servlet的提交
servlet的提交和动态改变有点依赖xml
我们点击控件的时候改变了里面的变量,改变了xml,servlet发现变量变了,就会刷新页面
如果xml文档没有更新,浏览器采用缓存而不则行
<form action='"+requestURI+"'method='get'>
<input type='text' name='param' value='param string'>
<input type='submit' value='用get方式查询"+requestURI+"'></form>
action后面接要发到文档的url,(这个代码是发到自己那里,然后自己的文档更新了,页面也动态更新)
method是我们人为控制用什么方法(get/post
后面有些变量,比如 param...我们后面可以用String param=request.getParameter("param");来获得他

package servlet; import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class FirstServlet extends HttpServlet { /**
* Constructor of the object.
*/
public FirstServlet() {
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 {
this.execute(request,response);
} /**
* 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 {
this.execute(request,response);
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void execute(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
this.log("则行doget方法");
response.setCharacterEncoding("UTF-8");
request.setCharacterEncoding("UTF-8");
String requestURI=request.getRequestURI();
String method=request.getMethod();
String param=request.getParameter("param");
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(method+"方式访问该页面。取到的para参数是"+param+"<br/>");
out.println("<form action='"+requestURI+"'method='get'><input type='text' name='param' value='param string'><input type='submit' value='用get方式查询"+requestURI+"'></form>");
out.println("<form action='"+requestURI+"'method='post'><input type='text' name='param' value='param string'><input type='submit' value='用post方式查询"+requestURI+"'></form>");
out.println("<script>document.write('本页面最后更新时间'+document.lastModified);</script>");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void init() throws ServletException {
// Put your code here
} }
servlet的提交的更多相关文章
- servlet自动获取前端页面提交数据
servlet自动获取前端页面jsp提交数据 以下是本人在学习过程中,因前端页面提交参数过多,后台servlet封装实体类过于麻烦而写的一个工具类,应用于jsp/servlet数据提交后,基于MVC+ ...
- ajax提交数据到java后台,并且返回json格式数据前台接收处理值
1.前台html页面.有一段代码如下: 账 户: <input type="text" name="userName" id="userN& ...
- WEB启动时就加载servlet的dopost方法
web启动的时候可以加载servlet的init方法,无法加载dopost方法,如果你需要什么内容在启动的时候执行,可以将内容放到init方法里面,dopost方法,是在客户端使用post请求的时候才 ...
- 5.servlet cookie自动登录的实例
1.要建的文档,.java用servlet创建 2.建一张登陆表格 index.jsp <%@ page language="java" import="java. ...
- JavaWeb 之 重复提交表单和验证码相关的问题!
下面我们首先来说一下表单的重复提交问题,我们知道在真实的网络环境中可能受网速带宽的原因会造成页面中表单在提交的过程中出现网络的延迟等问题,从而造成多次提交的问题!下面我们就具体来分析一下造成表单提交的 ...
- Servlet接收JSP参数乱码问题解决办法
转自:http://lavasoft.blog.51cto.com/62575/274527/ 环境: apache-tomcat-6.0.24.zip jdk1.6.0_16 WindosXP ...
- jsp+servlet+javaBean+Dao
一.Servlet程序各模块介绍1.JSP 用于显示.收集数据的部分.2.Servlet 用于验证数据.实例化JavaBean.调用DAO连接数据库.控制页面跳转3.DAO 用于连接数据库及进行数据库 ...
- servlet学习总结
一.web工程结构 1.HTTP协议(hyper text transfer protocol)(超文本传输协议) 机制:请求/响应 机制(request/response)(HttpServletR ...
- Servlet 2.3 规范
Servlet2.3规范 第一章: servlet2.3规范用到了一下的一些规范:J2EE.JSP1.1.JNDI 在14章中讲述了规范中的所有的classes类或接口(改文中不讲述).对开发者而言以 ...
随机推荐
- [Linux&Vim]基础01
学习和使用Linux有一段时间了,作为这么长时间的学习应该是有一定收获的,可惜的是没有一股专研精神,只停留在皮毛. 阅读过一些大牛们学习Linux和Vim的过程,从命令.环境配置.使用个性化设置.编程 ...
- 客户端MapReduce提交到YARN过程
在Mapreduce v1中是使用JobClient来和JobTracker交互完成Job的提交,用户先创建一个Job,通过JobConf设置好参数,通过JobClient提交并监控Job的进展,在J ...
- bzoj4448 SCOI2015 情报传递 message
传送门bzoj4448 题解 离线之后构建树上主席树,每个点的线段树维护到根路径的信息,不用链剖(我的链剖只是拿来求\(\mathrm{lca}\)的),时空复杂度\(O(n\log{n})\). c ...
- linux操作系统cron详解
Linux操作系统定时任务系统 Cron 入门 cron是一个linux下的定时执行工具,可以在无需人工干预的情况下运行作业.由于Cron 是Linux的内置服务,但它不自动起来,可以用以下的方法启动 ...
- 个人收藏的flex特效网址【经典中的极品】
http://www.noupe.com/adobe/flex-developers-toolbox-free-components-themes-and-tutorials.html经典中的经典 h ...
- 《sqlite权威指南》读书笔记 (一)
一 常量 字符串常量 (使用单引号括住.如果常量中有单引号,使用两个单引号来表示.大小写敏感) 数字常量 二进制常量 二 关键字 关键字大小写不敏感 三 注释 单行注释使用 --XXXXXXX 多 ...
- mysql内核源代码深度解析 缓冲池 buffer pool 整体概述
http://blog.csdn.net/cjcl99/article/details/51063078
- WCF - 绑定
从整个基础架构来看 WCF可分为服务模型层和信道层 模型层提供了一个统一的可扩展的编程模型 而信道层提供了对请求信息的接收和处理 而作为WCF通信的三要素之一的绑定 是它实现了组成整个信道层的信道栈 ...
- 多路复用的server模型
多路复用I/O之server模型 主要是关于select()这个函数: 其原型是:int select(int n,fd_set *read_fds,fd_set *write_fds,fd_set ...
- poj3348 Cows 凸包+多边形面积 水题
/* poj3348 Cows 凸包+多边形面积 水题 floor向下取整,返回的是double */ #include<stdio.h> #include<math.h> # ...