jsp文本框输入的中文值在另一个页面中当参数取出来是乱码
tomcat的server.xml文件已设置好了URIEncoding="GBK",页面上<%@pagelanguage="java"contentType="text/...
tomcat的server.xml文件已设置好了URIEncoding="GBK",页面上<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
先看程序:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*, java.util.Date, java.text.*, cn.jlu.project.mybase.*" %>
<html>
<head>
<title>添加产品页面</title>
<script type="text/javascript">
function check() {
var p_name = document.getElementById("p_name").value;
var p_price = document.getElementById("p_price").value;
var p_weight = document.getElementById("p_weight").value;
var p_desc = document.getElementById("p_desc").value;
if(p_name == "") {
alert("产品名称不能为空!");
return false;
}else if(p_price == "") {
alert("产品单价不能为空!");
return false;
}else if(p_weight == "") {
alert("产品重量不能为空!");
return false;
}else if(p_desc == "") {
alert("产品描述不能为空!");
return false;
}
return true;
}
</script>
</head>
<body>
<%@ include file="Head.jsp"%>
<div align="center">
<form action="ProductAdd.jsp" method="post">
<table>
<tr>
<td align="right" width="100">产品的名称:</td>
<td><input type="text" name="p_name" id="p_name"></td>
</tr>
<tr>
<td align="right" width="100">产品的单价:</td>
<td><input type="text" name="p_price" id="p_price"></td>
</tr>
<tr>
<td align="right" width="100">产品的重量:</td>
<td><input type="text" name="p_weight" id="p_weight"></td>
</tr>
<tr>
<td align="right" width="100">产品的描述:</td>
<td><input type="text" name="p_desc" id="p_desc"></td>
</tr>
<tr>
<td align="right" width="100"></td>
<td><input type="submit" name="submit" value="提交产品数据" onclick="javascript:return check()"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
第二个页面:
<body>
<%@ include file="Head.jsp"%>
<%
String p_name = request.getParameter("p_name");
double p_price = Double.parseDouble(request.getParameter("p_price"));
double p_weight = Double.parseDouble(request.getParameter("p_weight"));
String p_desc = request.getParameter("p_desc");
out.println(p_name);
%>
</body>
第一个页面输入长笛,第二个页面打印出?¤??
我另外一段代码直接传中文参数就没问题,这个从文本框里取就不行了。求解!! 展开
先看程序:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.sql.*, java.util.Date, java.text.*, cn.jlu.project.mybase.*" %>
<html>
<head>
<title>添加产品页面</title>
<script type="text/javascript">
function check() {
var p_name = document.getElementById("p_name").value;
var p_price = document.getElementById("p_price").value;
var p_weight = document.getElementById("p_weight").value;
var p_desc = document.getElementById("p_desc").value;
if(p_name == "") {
alert("产品名称不能为空!");
return false;
}else if(p_price == "") {
alert("产品单价不能为空!");
return false;
}else if(p_weight == "") {
alert("产品重量不能为空!");
return false;
}else if(p_desc == "") {
alert("产品描述不能为空!");
return false;
}
return true;
}
</script>
</head>
<body>
<%@ include file="Head.jsp"%>
<div align="center">
<form action="ProductAdd.jsp" method="post">
<table>
<tr>
<td align="right" width="100">产品的名称:</td>
<td><input type="text" name="p_name" id="p_name"></td>
</tr>
<tr>
<td align="right" width="100">产品的单价:</td>
<td><input type="text" name="p_price" id="p_price"></td>
</tr>
<tr>
<td align="right" width="100">产品的重量:</td>
<td><input type="text" name="p_weight" id="p_weight"></td>
</tr>
<tr>
<td align="right" width="100">产品的描述:</td>
<td><input type="text" name="p_desc" id="p_desc"></td>
</tr>
<tr>
<td align="right" width="100"></td>
<td><input type="submit" name="submit" value="提交产品数据" onclick="javascript:return check()"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
第二个页面:
<body>
<%@ include file="Head.jsp"%>
<%
String p_name = request.getParameter("p_name");
double p_price = Double.parseDouble(request.getParameter("p_price"));
double p_weight = Double.parseDouble(request.getParameter("p_weight"));
String p_desc = request.getParameter("p_desc");
out.println(p_name);
%>
</body>
第一个页面输入长笛,第二个页面打印出?¤??
我另外一段代码直接传中文参数就没问题,这个从文本框里取就不行了。求解!! 展开
1个回答
展开全部
第二个页面:post 方法中文处理
<body>
<%@ include file="Head.jsp"%>
<%
request.setCharacterEncoding("GBK");
String p_name = request.getParameter("p_name");
double p_price = Double.parseDouble(request.getParameter("p_price"));
double p_weight = Double.parseDouble(request.getParameter("p_weight"));
String p_desc = request.getParameter("p_desc");
out.println(p_name);
%>
</body>
<body>
<%@ include file="Head.jsp"%>
<%
request.setCharacterEncoding("GBK");
String p_name = request.getParameter("p_name");
double p_price = Double.parseDouble(request.getParameter("p_price"));
double p_weight = Double.parseDouble(request.getParameter("p_weight"));
String p_desc = request.getParameter("p_desc");
out.println(p_name);
%>
</body>
追问
最上头的已经处理了啊,篇幅所限我没写。上头写过了下头还需要post处理吗?
追答
第二个页面首句必须 request.setCharacterEncoding("GBK");
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询