中文乱码问题

来源:4-2 session对象

干巴爹forever

2017-10-29 15:33

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

<% request.setCharacterEncoding("utf-8");

  %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

    

    <title>My JSP 'session_page1.jsp' starting page</title>

    

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">    

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->


  </head>

  

  <body>

  <%

  session.setAttribute("username","admin");

  session.setAttribute("password","123456");

  session.setAttribute("habit","play games");

  

   %>

  创建时间:<%=session.getCreationTime() %></br>

  创建id:<%=session.getId() %></br>

 获得的属性 <%=session.getAttribute("username") %></br>

  

  


  </body>

</html>


写回答 关注

2回答

  • qq_浅紫色梦境_0
    2017-10-29 20:15:43
    已采纳

    request.setCharacterEncoding("UTF-8");       你可以试试看这个

    干巴爹for...

    有毒,我之前试过都不可以。。复制的你的代码就可以。。。我记得和大小写无关啊utf-8

    2017-10-29 20:28:25

    共 1 条回复 >

  • study_everyday
    2017-11-01 23:41:07

    URL传参修改tomcat配置config文件

JAVA遇见HTML——JSP篇

Java Web入门级教程JSP,带你轻松的学习JSP基础知识

248277 学习 · 3071 问题

查看课程

相似问题