zoukankan      html  css  js  c++  java
  • servlet 路径 编码 问题

    一 路径 编码 问题

    package com.itstaredu.servlet;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    
    /**
     * 使用绝对路径
     * /项目名/......
     * 绝对路径以/开头
     * 转发时候 dispatcher 不需要 项目名 因为在同一个项目下
     * 服务器解析 会带有项目名 不要加
     * 浏览器解析没有项目名 我们自己加
     * base标签 <base href="http://localhost:8080/javaweb07/"/> 后面加相对路径
     * 绝对路径以/开头
     * 相对路径 没有/开头
     * 编码问题 ISO-8859-1
     * 服务器 重新解码 再编码
     * request 在server.xml 65行 connector标签 添加 URIEncoding="UTF-8" 或无
     * <p>
     * request.setCharacterEncoding("UTF-8");
     * response.setContentType("text/html;charset=UTF-8");
     * response.setHeader("content-Type","text/html;charset=UTF-8");
     */
    public class PathServlet extends HttpServlet {
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
        }
    
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("UTF-8");
            response.setContentType("text/html;charset=UTF-8");
    
            response.getWriter().write("三国志");
            String name = request.getParameter("username0");
            System.out.println(name);
        }
    }
    

      

  • 相关阅读:
    Codeforces Round #535 (Div. 3)
    2019 CCPC-Wannafly Winter Camp Day4(Div2, onsite)
    Codeforces Round #534 (Div. 2)
    2019 CCPC-Wannafly Winter Camp Day3(Div2, onsite)
    2019 CCPC-Wannafly Winter Camp Day2(Div2, onsite)
    2019 CCPC-Wannafly Winter Camp Day1 (Div2, onsite)
    codeforces1097D Makoto and a Blackboard 数学+期望dp
    【NOIP2016】换教室
    ICPC2019徐州站游记
    【Codeforces】Orz Panda Cup
  • 原文地址:https://www.cnblogs.com/liubosong/p/11989352.html
Copyright © 2011-2022 走看看