请教jsp乱码问题

下个路口见_20 2014-10-24 11:17:15
楼主写了两个jsp页面
第一个jsp:
 <body>
<form action="Jsptest.jsp">
姓名:<input type="text" name="username"/><br/><br/>
年龄:<input type="text" name="userage"/><br/><br/>
系别:<input type="text" name="usersdept"/><br/><br/>
<input type="submit" value="提交"/>
</form>
</body>


第二个jsp:

<body bgcolor="#FFFFFF">

<jsp:useBean id="student" class="aaa.javabeantest" scope="page"/>
<jsp:setProperty name="student" property="name" param="username"/>
<jsp:setProperty name="student" property="age" param="userage"/>
<jsp:setProperty name="student" property="sdept" param="usersdept"/><br/>


姓名:
<jsp:getProperty name="student" property="name" />
<br/>
年龄:
<jsp:getProperty name="student" property="age" />
<br/>
院系:
<jsp:getProperty name="student" property="sdept" />

</body>


输入英文、数字的时候,显示都正常,但输入中文的时候就乱码,找了很多方法,效果都不好。求高手指导!!!
...全文
209 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
空道人 2014-10-25
  • 打赏
  • 举报
回复
你代码中的head标签中的这句<meta http-equiv="Content-Type" content="text/html; charset=gb2312">,请把中间的gb2312改为utf-8
shixitong 2014-10-24
  • 打赏
  • 举报
回复
1、把页面贴全,让大家看到页面编码 2、form以post方式提交 <form action="Jsptest.jsp" method=“post”>
下个路口见_20 2014-10-24
  • 打赏
  • 举报
回复
引用 1 楼 w405112941 的回复:
统一页面的编码、项目的编码、tomcat的编码和数据库的编码。 servlet/action中输出接收到的参数看看有没有乱码 在跳转到页面前输出传递到页面的参数看看有没有乱码 确定乱码出现的位置,再来处理
听着好高大上的样子,我刚学的javabean,想在第二个jsp页面输出第一个jsp页面的信息,汉字乱码,我加了一个过滤器和Servlet,但是还是没有效果,不知道该怎么办了。
The_end90 2014-10-24
  • 打赏
  • 举报
回复
统一页面的编码、项目的编码、tomcat的编码和数据库的编码。 servlet/action中输出接收到的参数看看有没有乱码 在跳转到页面前输出传递到页面的参数看看有没有乱码 确定乱码出现的位置,再来处理
qq_22465835 2014-10-24
  • 打赏
  • 举报
回复
zhouxiaoyong123 2014-10-24
  • 打赏
  • 举报
回复
1.首先你把编码格式配置为utf-8 2.配置自定义编码过滤 在你的web.xml中配置 <filter> <filter-name>encodingFilter</filter-name> <filter-class>指你自定义的包点类名称(如:com .ch .demo.filter.Encdoing )r</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> new一个自定义的过滤器类,extends HttpServlet implements Filter public class Encdoing extends HttpServlet implements Filter { private FilterConfig filterConfig; private String trargetEncoding=null; /**执行过滤编码**/ public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterchain) throws IOException, ServletException { //打印编码 request.setCharacterEncoding(trargetEncoding); filterchain.doFilter(request, response); } /**初始化执行方法**/ public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig=filterConfig; this.trargetEncoding=this.filterConfig.getInitParameter("encoding"); } /**清空资源**/ public void destory(){ this.filterConfig=null; this.trargetEncoding=null; } } 试试这个应该可以了吧! 如果还不行,请把具体乱码信息帖出来
周先生xs 2014-10-24
  • 打赏
  • 举报
回复
我解决乱码都是采用跟踪数据 ,哪乱在哪处理。
回锅菜鸟 2014-10-24
  • 打赏
  • 举报
回复
在你的servle中,添加上这两句话试试 //浏览器传到服务器 request.setCharacterEncoding("UTF-8");   //服务器传到浏览器 response.setContentType("text/html;charset=UTF-8"));
下个路口见_20 2014-10-24
  • 打赏
  • 举报
回复
引用 3 楼 shixitong 的回复:
1、把页面贴全,让大家看到页面编码 2、form以post方式提交 <form action="Jsptest.jsp" method=“post”>
form.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'form.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>
    <form action="s" method="post">
    姓名:<input type="text" name="username"/><br/><br/>
    年龄:<input type="text" name="userage"/><br/><br/>
    系别:<input type="text" name="usersdept"/><br/><br/>
    <input type="submit" value="提交"/>
   </form>
  </body>
</html>
Jsptest.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

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


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'Jsptest.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">
	<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body bgcolor="#FFFFFF">
  
   <jsp:useBean id="student" class="aaa.javabeantest" scope="page"/>
   <jsp:setProperty name="student" property="name" param="username"/>
   <jsp:setProperty name="student" property="age" param="userage"/>
   <jsp:setProperty name="student" property="sdept" param="usersdept"/><br/>
   
  
   姓名:
   <jsp:getProperty name="student" property="name" />
   <br/>
   年龄:
    <jsp:getProperty name="student" property="age" />
    <br/>
    院系:
     <jsp:getProperty name="student" property="sdept" />
   
  </body>
</html>

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧