标签:web 默认 head XML 正文 编码 tle ring web服务器
public void addDateHeader(java.lang.String name,long date)
public void addHeader(java.lang.String name, java.lang.String value)
public void addIntHeader(java.lang.String name, int value)
public boolean containsHeader(java.lang.String name)
public void setHeader(java.lang.String name, java.lang.String value)
public void setIntHeader(java.lang.String name,int value)
public void setDateHeader(java.lang.String name, long date)
public ServletOutputStream getOutputStream() throws java.io.IOException
public java.io.PrintWriter getWriter() throws java.io.IOException
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String data = "我爱你"; OutputStream out = response.getOutputStream(); out.write(data.getBytes());//String 的getBytes()默认在windows系统中默认上的是GBK } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>ResponseDemo1</servlet-name> <servlet-class>com.servlet.ResponseDemo1</servlet-class> </servlet> <servlet-mapping> <servlet-name>ResponseDemo1</servlet-name> <url-pattern>/responseDemo1</url-pattern> </servlet-mapping> </web-app>
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String data = "我爱你"; OutputStream out = response.getOutputStream(); out.write(data.getBytes("utf-8"));//String 的getBytes()默认在windows系统中默认上的是GBK } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <servlet> <servlet-name>ResponseDemo1</servlet-name> <servlet-class>com.servlet.ResponseDemo1</servlet-class> </servlet> <servlet-mapping> <servlet-name>ResponseDemo1</servlet-name> <url-pattern>/responseDemo1</url-pattern> </servlet-mapping> </web-app>
<meta http-equiv=‘Content-Type‘ content=‘text/html;charset=UTF-8‘>
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String data = "我爱你"; OutputStream out = response.getOutputStream(); out.write("<meta http-equiv=‘Content-Type‘ content=‘text/html;charset=UTF-8‘>".getBytes()); out.write(data.getBytes("utf-8"));//String 的getBytes()默认在windows系统中默认上的是GBK } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Content-Type","text/html;charset=UTF-8"); String data = "我爱你"; OutputStream out = response.getOutputStream(); out.write(data.getBytes("utf-8"));//String 的getBytes()默认在windows系统中默认上的是GBK } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String data = "我爱你"; OutputStream out = response.getOutputStream(); out.write(data.getBytes("utf-8"));//String 的getBytes()默认在windows系统中默认上的是GBK } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String data = "我爱你"; PrintWriter out = response.getWriter(); out.print(data); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); String data = "我爱你"; PrintWriter out = response.getWriter(); out.print(data); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; /** * 2017/11/5 * 说明: */ public class ResponseDemo1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); String data = "我爱你"; PrintWriter out = response.getWriter(); out.print(data); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 2017/11/5 * 说明: */ public class ResponseDemo2 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("refresh","2;URL=http://www.baidu.com"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 2017/11/5 * 说明: */ public class ResponseDemo3 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //清除缓存 response.setHeader("expires","-1"); response.setHeader("pragma","no-cache"); response.setHeader("cache-control","no-cache"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 2017/11/5 * 说明: */ public class ResponseDemo3 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setStatus(302); response.setHeader("location",request.getContextPath()+"/responseDemo2"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 2017/11/5 * 说明: */ public class ResponseDemo3 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.sendRedirect(request.getContextPath()+"/responseDemo2"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
public java.lang.String getMethod()
public java.lang.String getRequestURI()
public java.lang.StringBuffer getRequestURL()
public java.lang.String getProtocol()
public java.lang.String getParameter(java.lang.String name)
public java.lang.String[] getParameterValues(java.lang.String name)
public java.util.Enumeration getParameterNames()
public java.util.Map getParameterMap()
public ServletInputStream getInputStream()
public java.lang.String getRemoteAddr()
package com.servlet; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; /** * 2017/11/5 * 说明: */ public class RequestServlet1 extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); String method = request.getMethod();//获取请求方式 String uri = request.getRequestURI(); String url = request.getRequestURL().toString(); String protocol = request.getProtocol(); String ip = request.getRemoteAddr();//ip response.getWriter().println("方法:"+method+"<br/>"); response.getWriter().println("uri:"+uri+"<br/>"); response.getWriter().println("url:"+url+"<br/>"); response.getWriter().println("protocol:"+protocol+"<br/>"); response.getWriter().println("ip:"+ip+"<br/>"); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册</title> </head> <body> <table> <form action="${pageContext.request.contextPath}/register" method="post"> <tr> <td>用户名</td> <td> <input type="text" name="username"/> </td> </tr> <tr> <td>密码</td> <td> <input type="password" name="password"/> </td> </tr> <tr> <td>爱好</td> <td> <input type="checkbox" name="hobby" value="游戏"/>游戏 <input type="checkbox" name="hobby" value="开发"/>开发 <input type="checkbox" name="hobby" value="电视"/>电视 </td> </tr> <tr> <td colspan="2"> <input type="submit" value="注册"/> </td> </tr> </form> </table> </body> </html>
package com.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Arrays; /** * 2017/11/5 * 说明: */ public class RegisterServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); String[] hobby = request.getParameterValues("hobby"); System.out.println("用户名:"+username); System.out.println("密码:"+password); System.out.println("爱好:"+ Arrays.toString(hobby)); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Arrays; /** * 2017/11/5 * 说明: */ public class RegisterServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); String username = request.getParameter("username"); String password = request.getParameter("password"); String[] hobby = request.getParameterValues("hobby"); System.out.println("用户名:"+username); System.out.println("密码:"+password); System.out.println("爱好:"+ Arrays.toString(hobby)); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
package com.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Arrays; /** * 2017/11/5 * 说明: */ public class RegisterServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); String[] hobby = request.getParameterValues("hobby"); System.out.println("用户名:"+username); System.out.println("密码:"+password); System.out.println("爱好:"+ Arrays.toString(hobby)); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request,response); } }
标签:web 默认 head XML 正文 编码 tle ring web服务器
原文地址:http://www.cnblogs.com/xuweiweiwoaini/p/7783553.html