Servlet的HttpServletResponse输出
了解其中的一些字符设置,PrintWriter输出等。。
form.html:
<!DOCTYPE html> <html> <head> <title>宠物类型大调查</title> <meta http-equiv="content-type" content="text/html ;charset=UTF-8"> </head> <body> <form method="post" action="pet" > 姓名:<input type="text" name="user" value=""><br> 邮件:<input type="text" name="email" value=""><br> 你喜爱的宠物代表: <br> <select name="type" size="6" multiple="true"> <option value="猫">猫</option> <option value="狗">狗</option> <option value="鱼">鱼</option> <option value="鸟">鸟</option> </select> <br> <input type="submit" value="send" /> </form> </body> </html>
Pet.java:
package cc.openhome;
import java.io.IOException;
import java.io.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Pet
*/
@WebServlet("/pet")
public class Pet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Pet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>感谢填写</title>");
out.println("</head>");
out.println("<body>");
out.println("联系人:<a herf='mailto:"
+ request.getParameter("email") + "'>"
+ request.getParameter("user") + "</a>");
out.println("<br>喜爱的宠物类型");
for (String type : request.getParameterValues("type")) {
out.println("<li>" + type + "</li>");
}
out.println("<ul>");
out.println("</ul>");
out.println("</body>");
out.println("</html>");
out.close();
}
}

Servlet的HttpServletResponse输出的更多相关文章
- Servlet的response输出到页面时乱码的解决方法
package com.mhb; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.Servle ...
- HttpServletResponse输出的中文乱码
HttpServletResponse输出有两种格式,一种是字符流,一种是字节流. 1.字符流 // 这句话的意思,是让浏览器用utf8来解析返回的数据,即设置客户端解析的编码 response.se ...
- servlet向浏览器输出信息
package com.aaa.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebS ...
- [spring]启动时报错:NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
Spring V4.1以后的版本在不支持Servlet3.0的应用服务器上跑时会报如下错误: NoSuchMethodError: javax.servlet.http.HttpServletResp ...
- The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from required .class files
The type javax.servlet.http.HttpServletResponse cannot be resolved. It is indirectly referenced from ...
- Servlet (三)HttpServletResponse
package cn.sasa.serv; import java.io.IOException; import javax.servlet.ServletException; import java ...
- javax.servlet.http.HttpServletResponse.getStatus()I
感谢作者分享:http://blog.csdn.net/szwangdf/article/details/42145463 -------------------------------------- ...
- servlet 让浏览器输出中文,并成功打印出来.2种方法
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; impor ...
- Java-API:javax.servlet.http.HttpServletResponse
ylbtech-Java-API:javax.servlet.http.HttpServletResponse 1.返回顶部 1. javax.servlet.http Interface HttpS ...
随机推荐
- ubuntu16.04 Kafka 安装
Kafka核心概念: 下面介绍Kafka相关概念,以便运行下面实例的同时,更好地理解Kafka. 1. Broker Kafka集群包含一个或多个服务器,这种服务器被称为broker 2. Topic ...
- $CF1141C Polycarp Restores Permutation$
\(problem\) 这题的大致意思就是已知数值差值 求1-n的排列 如果能构成排列 则输出这个排列.如果不能则输出-1 排列的值都是 大于1 而小于n的 而且没有相同的数字. 这题最关键的是 怎么 ...
- [python] ThreadPoolExecutor线程池
初识 Python中已经有了threading模块,为什么还需要线程池呢,线程池又是什么东西呢?在介绍线程同步的信号量机制的时候,举得例子是爬虫的例子,需要控制同时爬取的线程数,例子中创建了20个线程 ...
- SVD 学习笔记
本文主要学习了这篇博客:http://www.cnblogs.com/LeftNotEasy/archive/2011/01/19/svd-and-applications.html,将SVD讲的恨透 ...
- flask web 表单验证 WTForms
简介 WTForms 是一个flask集成框架,或者说是库,用于处理浏览器表单提交的数据,它在flask-WTF的基础上扩展并添加了一些随手可得的精巧帮助函数,这些函数将会是在flask里使用表单更加 ...
- Elasticsearch之CURL命令的GET
这是个查询命令. 前期博客 Elasticsearch之CURL命令的PUT和POST对比 1. 以上是根据员工id查询. 即在任意的查询字符串中添加pretty参数,es可以得到易于我们识别的jso ...
- [转]android 让一个控件按钮居于底部的几种方法
本文转自:http://www.cnblogs.com/zdz8207/archive/2012/12/13/2816906.html android 让一个控件按钮居于底部的几种方法 1.采用lin ...
- [转]Linux下/proc目录简介
1. /proc目录Linux 内核提供了一种通过 /proc 文件系统,在运行时访问内核内部数据结构.改变内核设置的机制.proc文件系统是一个伪文件系统,它只存在内存当中,而不占用外存空间.它以文 ...
- [转]Learn SQLite in 1 hour
转载说明: 1.原文地址:http://www.askyb.com/sqlite/learn-sqlite-in-1-hour/ 2.译文地址:http://www.oschina.net/quest ...
- python2升级成python3
系统环境centos 6.5原python版本2.6.6目标python版本3.5.11.下载python3.5wget --no-check-certificate http://www.pyth ...