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的提交的更多相关文章

  1. servlet自动获取前端页面提交数据

    servlet自动获取前端页面jsp提交数据 以下是本人在学习过程中,因前端页面提交参数过多,后台servlet封装实体类过于麻烦而写的一个工具类,应用于jsp/servlet数据提交后,基于MVC+ ...

  2. ajax提交数据到java后台,并且返回json格式数据前台接收处理值

    1.前台html页面.有一段代码如下: 账  户:  <input type="text" name="userName" id="userN& ...

  3. WEB启动时就加载servlet的dopost方法

    web启动的时候可以加载servlet的init方法,无法加载dopost方法,如果你需要什么内容在启动的时候执行,可以将内容放到init方法里面,dopost方法,是在客户端使用post请求的时候才 ...

  4. 5.servlet cookie自动登录的实例

    1.要建的文档,.java用servlet创建 2.建一张登陆表格 index.jsp <%@ page language="java" import="java. ...

  5. JavaWeb 之 重复提交表单和验证码相关的问题!

    下面我们首先来说一下表单的重复提交问题,我们知道在真实的网络环境中可能受网速带宽的原因会造成页面中表单在提交的过程中出现网络的延迟等问题,从而造成多次提交的问题!下面我们就具体来分析一下造成表单提交的 ...

  6. Servlet接收JSP参数乱码问题解决办法

    转自:http://lavasoft.blog.51cto.com/62575/274527/   环境: apache-tomcat-6.0.24.zip jdk1.6.0_16 WindosXP ...

  7. jsp+servlet+javaBean+Dao

    一.Servlet程序各模块介绍1.JSP 用于显示.收集数据的部分.2.Servlet 用于验证数据.实例化JavaBean.调用DAO连接数据库.控制页面跳转3.DAO 用于连接数据库及进行数据库 ...

  8. servlet学习总结

    一.web工程结构 1.HTTP协议(hyper text transfer protocol)(超文本传输协议) 机制:请求/响应 机制(request/response)(HttpServletR ...

  9. Servlet 2.3 规范

    Servlet2.3规范 第一章: servlet2.3规范用到了一下的一些规范:J2EE.JSP1.1.JNDI 在14章中讲述了规范中的所有的classes类或接口(改文中不讲述).对开发者而言以 ...

随机推荐

  1. 织梦CMS(dedecms)栏目属性及系统封面模板、列表模板、文章模板区别和路径设置解答

    问题一:(织梦"栏目管理"的"常规选项"中3个栏目属性分析?) 织梦CMS的栏目属性分成三种, -->最终列表栏目 -->频道封面 -->外部 ...

  2. Hibernate(二)Hibernate 实例

    上篇Hibernate(一)JDBC简介,我们主要对JDBC进行了简单介绍和使用说明,这次我们做一个Hibernate简单实例,通过这个实例对比Hibernate和JDBC,了解Hibernate的优 ...

  3. 400. Nth Digit

    这个EASY难度的题怎么感觉比H的还难,昨天没做出来,今天才做出来.. 呃啊..我生 气 啦.. 直接看的答案,耻辱. 1 digit: 1~9 总共1×9个 2 digits: 10~99 总共2× ...

  4. 深入浅出node(4) 异步编程

    一)函数式编程基础 二)异步编程的优势和难点 2.1 优势 2.2 难点 2.2.1 异常处理 2.2.2 函数嵌套过深 2.2.3 阻塞 2.2.4 多线程编程 2.2.5 异步转同步 三)异步编程 ...

  5. 用Python实现常见排序算法

    最简单的排序有三种:插入排序,选择排序和冒泡排序.这三种排序比较简单,它们的平均时间复杂度均为O(n^2),在这里对原理就不加赘述了.贴出来源代码. 插入排序: def insertion_sort( ...

  6. Tomcat工作原理(转)

    Tomcat简介 作者:杨晓(http://blog.sina.com.cn/u/1237288325) 一.Tomcat背景 自从JSP发布之后,推出了各式各样的JSP引擎.Apache Group ...

  7. 弹出窗口zDialog的使用

    因为没有元素可以显示到Frameset上面去,所以重新定义了,一个index.htm,对其的操作是: Index.htm    <script language="javascript ...

  8. Microsoft office word关闭英文输入首字母大写设置

    1.概述: 在使用office word的时,经常出现输入一段不需首字母大写的英文时,通常敲击完回车时word会自动将首字母大写,需要重新将首字母修改成小写,这样操作很不方便.于是需要对这个功能进行一 ...

  9. [RxJS] Stream Processing With RxJS vs Array Higher-Order Functions

    Higher order Array functions such as filter, map and reduce are great for functional programming, bu ...

  10. Android 判断数据库中是否存在某个表

    public boolean tabIsExist(String tabName){ boolean result = false; if(tabName == null){ return false ...