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. 买错的电影票,含着泪也得看-LAMP搭建&Linux基础

    hi 没说过,上周五室友过生请客,在龙湖里吃嗨了喝爽了,回去的路上侃侃而谈.说好的这周一起去看年内最后的大片,火星救援的,谁知道老子眼神不好,买错了电影的时间...把周六的约定提前到了今儿个下午,ma ...

  2. BestCoder Round #87 1003 LCIS[序列DP]

    LCIS  Accepts: 109  Submissions: 775  Time Limit: 4000/2000 MS (Java/Others)  Memory Limit: 65536/65 ...

  3. Codeforces 500B. New Year Permutation[连通性]

    B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Unity游戏暂停之Update与FixedUpdate区别

    游戏暂停 示例程序 下面这段代码演示游戏暂停 using UnityEngine; using System.Collections; public class GamePauseTest : Mon ...

  5. hdu 1542 & & poj 1151

    Atlantis Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  6. java(搜索不区分大小写)

    ref.put("myfield", Pattern.compile(".*myValue.*" , Pattern.CASE_INSENSITIVE));

  7. TabBarController

    1.两种方式创建系统TabBarController -(id)init{ self = [super init]; if( self ) { //newTask HSNewTaskViewContr ...

  8. 对于多个列的转行(一个值均匀分布在两个列中),对于个别字段通过取别名,join方式解决。

    例如,这个表的结构: select r.* from RPDATA2016 r WHERE r.data_bbid='HY052' 如图 对于最后两列,如果是字符类型,会存在倒数第二列,是数字类型,会 ...

  9. Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

    Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. ...

  10. office 2010 2013卸载工具

    http://www.ithome.com/html/soft/32777.htm Office 2003 || Office 2007 || Office 2010.