html表单提交 JSP显示乱码
我的前台是HTML页面做的,提交一些表单,后面用JSP页面来获前台提交值但在获取后显示出来的是乱码,不知道怎么解决,代码如下HTML页面-----------------...
我的前台是HTML页面做的,提交一些表单,后面用JSP页面来获前台提交值
但在 获取后显示出来的是乱码,不知道怎么解决,代码如下
HTML页面
------------------------------------------------------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<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=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form name="form1" action="test2.jsp" method="post">
<input type="text" name="text1">
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
-----------------------------------------------------------------
JSP页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page contentType="text/html;charset=GBK"%>
<%
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 'test2.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>
<%String name=new String (request.getParameter("text1").getBytes("iso-8859-1")); %>
<%=name %>
</body>
</html> 展开
但在 获取后显示出来的是乱码,不知道怎么解决,代码如下
HTML页面
------------------------------------------------------------------<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test.html</title>
<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=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
</head>
<body>
<form name="form1" action="test2.jsp" method="post">
<input type="text" name="text1">
<input type="submit" name="submit" value="提交">
</form>
</body>
</html>
-----------------------------------------------------------------
JSP页面
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page contentType="text/html;charset=GBK"%>
<%
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 'test2.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>
<%String name=new String (request.getParameter("text1").getBytes("iso-8859-1")); %>
<%=name %>
</body>
</html> 展开
4个回答
展开全部
如果是tomcat修改server.xml
增加 URIEncoding="GBK"
<Connector port="8080" ...... URIEncoding="GBK"/>
可解决post提交的乱码.
get方法提交乱码可web.xml中增加filter
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>
org.....SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
类SetCharacterEncodingFilter可在tomcat自带的sample中找到.
增加 URIEncoding="GBK"
<Connector port="8080" ...... URIEncoding="GBK"/>
可解决post提交的乱码.
get方法提交乱码可web.xml中增加filter
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>
org.....SetCharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
类SetCharacterEncodingFilter可在tomcat自带的sample中找到.
展开全部
应该是中文处理问题吧。
<%
String path = request.getContextPath();
byte a[]=path.getBytes("ISO-8859-1");
path=new String(a);
out.println(path);
%>
上面这样处理应该就没有乱码,然后把
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
里面的值都通过如上面的值处理方法处理应该就可以了,试试看吧。
<%
String path = request.getContextPath();
byte a[]=path.getBytes("ISO-8859-1");
path=new String(a);
out.println(path);
%>
上面这样处理应该就没有乱码,然后把
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
里面的值都通过如上面的值处理方法处理应该就可以了,试试看吧。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page contentType="text/html;charset=GBK"%>
在第一个页面也加上这段代码,应该没问题了
<%@ page contentType="text/html;charset=GBK"%>
在第一个页面也加上这段代码,应该没问题了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你在第二页的<%%>内加上以下语句就行了
request.setCharacterEncoding("gb2312")
request.setCharacterEncoding("gb2312")
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询