1,表单页面 shangpin.html

 <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>商品信息</title>
</head>
<body> 商品信息<br> <form action="Shp" method="post"> 商品名称:<input type="text" name="name" >
<br>
商品类别:<input type="radio" name="kind" value="食品" checked>食品
<input type="radio" name="kind" value="办公用品">办公用品
<input type="radio" name="kind" value="服装">服装
<br>
商品简介:
<br>
<textarea rows="10" cols="20" name="intr"></textarea>
<br>
<input type="submit" value="提交"> </form> </body>
</html>

2.接收处理servlet: shp.java

 package com.hanqi;

 import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; /**
* Servlet implementation class Shp
*/
public class Shp extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public Shp() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
//指定字符集
response.setCharacterEncoding("GBK");
request.setCharacterEncoding("utf-8");
//获取表单提交信息
String name = request.getParameter("name");
String kind = request.getParameter("kind");
String intr = request.getParameter("intr"); // //Request字符集转换
// String zname = new String(name.getBytes("iso-8859-1"),"utf-8");
// String zkind = new String(kind.getBytes("iso-8859-1"),"utf-8");
// String zintr = new String(intr.getBytes("iso-8859-1"),"utf-8");
//
response.getWriter().append("商品名称:" + name + "; 商品类别:" + kind + "; 商品简介:" + intr); //response.getWriter().append("Served at: ").append(request.getContextPath());
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
// response.setCharacterEncoding("gbk");
// request.setCharacterEncoding("utf-8");
// //获取表单提交信息
// String name = request.getParameter("name");
// String kind = request.getParameter("kind");
// String intr = request.getParameter("intr");
//
// response.getWriter().append("商品名称:" + name + "; 商品类别:" + kind + "; 商品简介:" + intr); } }

Servlet作业2-将表单提交的商品信息输出到页面中的更多相关文章

  1. 怎么实现form表单提交后不重新刷新当前页面

    怎么实现表单提交后不重新刷新当前页面     如何实现表单提交后不重新刷新当前页面 <form name='form1' id='form1' action='/xbcw/cw/xx_xx.ac ...

  2. js form表单提交后如何可以不刷新页面 的解决办法

    表单可实现无刷新页面提交,无需页面跳转,如下: 通过一个隐藏的iframe实现, form表单的target设置为iframe的name名称,form提交目标位当前页面iframe则不会刷新页面 &l ...

  3. 关于form表单提交数据后不跳转页面+ajax接收返回值的处理

    1.前台的form表单建立,注意action.enctype的内容, 2.通过添加一个隐藏的iframe标签使form的target指向iframe来达到不跳转页面的效果,同时需要在js里获取ifra ...

  4. php让页面记住表单提交后的信息方法

    <body> <?php $name = $_POST['name']; echo $name; $gender = $_POST['gender']; echo $gender; ...

  5. 获取表单提交MVC错误信息

    if (!ModelState.IsValid)                {                    List<string> Keys = ModelState.Ke ...

  6. php分享表单提交到本页的实例

    我们在做表单提交时,一般都要设置表单的action属性,改属性用于指定表单提交到服务器上的哪个页面进行处理,但为空时,表示提交到本页进行处理,即提交给自己.本文章向大家分享表单提交给本页的实例. 实例 ...

  7. DWZ(JUI) 教程 普通表单提交

    一类是普通的表单提交,另一类就是列表页面的表单提交,主要是用来查询搜索列表使用的.今天我就简单介绍一下前者. 这是官网上的普通列表页面, <div class="pageContent ...

  8. Extjs 表单提交送给新手

    Extjs的三种提交方式: 表单Ajax提交,普通提交,单独Ajax提交: 1.表单ajax提交(默认提交方式) 提交函数:当按下表单中的提交按钮时执行下面的btn函数,按照表单的name进行提交.提 ...

  9. Extjs之表单提交

    Extjs的三种提交方式: 表单Ajax提交,普通提交,单独Ajax提交: 表单Ajax提交(默认提交方式) 提交函数:当按下表单中的提交按钮时执行下面的 btn函数,按照表单的 name进行提交. ...

随机推荐

  1. MMORPG大型游戏设计与开发(part5 of net)

    上一部分将服务器的具体代码的实现介绍给了大家,想必大家也了解到了服务器处理一次消息的复杂度.如果大家能够将各个过程掌握清楚,就会发觉其实整个逻辑与交互过程是比较清晰的.那么服务器与服务器之间的通讯,其 ...

  2. Codeforces 460D Little Victor and Set --分类讨论+构造

    题意:从区间[L,R]中选取不多于k个数,使这些数异或和尽量小,输出最小异或和以及选取的那些数. 解法:分类讨论. 设选取k个数. 1. k=4的时候如果区间长度>=4且L是偶数,那么可以构造四 ...

  3. IT菜鸟的3(for循环+分支语句)

    第三天学的东西感觉已经不是很容易能想通了,感觉头懵懵的,难道这就是是文科生的障碍吗,我不相信,坚持!相信自己一定会做好! 1:for循环!(1)循环四要素:初始条件,循环条件,循环体,状态改变for( ...

  4. [No00002E]关于大数据,你不知道的6个迷思

    还是那个观点:计算机,编程语言,互联网,大数据等等都只是工具! 导语:看过美剧<纸牌屋>没?知道这部"白宫甄嬛传"为什么会火吗?靠的是大!数!据! 过去两年,在 Net ...

  5. bzoj2548[Cstc2002]灭鼠行动

    Description 最近,有一些繁殖力很强的老鼠在下水道非常猖獗,灭鼠特工队正在计划消灭这些老鼠.下水道只有东西方向和南北方向的管道,如图所示. 灭鼠特工队的队员拥有强大的武器.他们将在某些时刻t ...

  6. uva167 The Sultan's Successors

    The Sultan's Successors Description The Sultan of Nubia has no children, so she has decided that the ...

  7. windows live Writer test

    package com.newegg.shopping.util.listener; import javax.servlet.http.HttpSessionAttributeListener; i ...

  8. 布局 - layout

    示例 <div id="cc" class="easyui-layout" style="width:600px;height:400px;&q ...

  9. codevs 2801 LOL-盖伦的蹲草计划

     时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题目描述 Description 众所周知,LOL这款伟大的游戏,有个叫盖伦的英雄.他的伟大之处在于他特别喜欢蹲 ...

  10. dotnetGen 系列终于开源了

    https://github.com/2881099/dotnetGen .Net 3.0 + SqlServer 生成器 https://github.com/2881099/dotnetGen_s ...