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类或接口(改文中不讲述).对开发者而言以 ...
随机推荐
- bzoj3209
首先这道题目不难想到将答案转化为这种形式 2^s[2]*3*s[3]*…max*s[max] 这时候我们要分类讨论,设n的二进制位数为t 当1~n中二进制位数小于t时 我们可以直接用组合的知识,二进制 ...
- 【转】Eclipse中设置ButterKnife进行注解式开发步骤 -- 不错
原文网址:http://www.bubuko.com/infodetail-974262.html 最近在进行Android注解式开发的学习,正在尝试用ButterKnife.ButterKnife的 ...
- ASP.Net 验证视图状态 MAC 失败
错误信息: 验证视图状态 MAC 失败.如果此应用程序由网络场或群集承载,请确保 <machineKey> 配置指定了相同的 validationKey 和验证算法.不能在群集中使用 Au ...
- vs未找到导入的项目,请确认 <Import> 声明中的路径正确
当使用vs出现下列情况: D:\xxxx\Web\Web.csproj : error : 无法读取项目文件“Web.csproj”. D:\xxxx\WebServiceManager\Web\W ...
- Linux学习笔记26——信号量
一 信号量的基本概念 信号量:它是一个特殊变量,只允许对它进行等待和发送信号这两种操作. 假设有一个信号量变量sv P(sv):用于等待,如果sv的值大于零,就给它减去1,如果它的值等于零,就挂起该进 ...
- leetcode排列,求第k个排列
stl 中的下一个排列在写一遍忘了 写个1个多小时,使用递归写的,错误就在我使用一个list保存当前剩下的数,然后利用k/(n-1)!的阶乘就是删除的数字,但进过观察, 比如 list={1,2,3} ...
- bzoj 2463 [中山市选2009]谁能赢呢?(博弈)
2463: [中山市选2009]谁能赢呢? Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1290 Solved: 944[Submit][Stat ...
- [转]C++ map容器用法
C++ map的基本操作和使用 原文地址:http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html Map是c++的一个标准容器,她提供了很好一对一的关 ...
- kafka consumer频繁reblance
转载请注明地址http://www.cnblogs.com/dongxiao-yang/p/5417956.html 结论与下文相同,kafka不同topic的consumer如果用的groupid名 ...
- 11个让你吃惊的Linux终端命令