jsp文本框输入的中文值在另一个页面中当参数取出来是乱码
答案:1 悬赏:0 手机版
解决时间 2021-02-06 20:40
- 提问者网友:雾里闻花香
- 2021-02-06 14:36
tomcat的server.xml文件已设置好了URIEncoding="GBK",页面上<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%><br><br>先看程序:<br><%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%><br><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><br><%@ page import="java.sql.*, java.util.Date, java.text.*, cn.jlu.project.mybase.*" %><br><html><br> <head><br> <title>添加产品页面</title><br> <script type="text/javascript"><br> function check() {<br> var p_name = document.getElementById("p_name").value;<br> var p_price = document.getElementById("p_price").value;<br> var p_weight = document.getElementById("p_weight").value;<br> var p_desc = document.getElementById("p_desc").value;<br> if(p_name == "") {<br> alert("产品名称不能为空!");<br> return false;<br> }else if(p_price == "") {<br> alert("产品单价不能为空!");<br> return false;<br> }else if(p_weight == "") {<br> alert("产品重量不能为空!");<br> return false;<br> }else if(p_desc == "") {<br> alert("产品描述不能为空!");<br> return false;<br> }<br> return true;<br> }<br> </script><br> </head><br><br> <body><br> <%@ include file="Head.jsp"%><br> <div align="center"><br> <form action="ProductAdd.jsp" method="post"><br> <table><br> <tr><br> <td align="right" width="100">产品的名称:</td><br> <td><input type="text" name="p_name" id="p_name"></td><br> </tr><br> <tr><br> <td align="right" width="100">产品的单价:</td><br> <td><input type="text" name="p_price" id="p_price"></td><br> </tr><br> <tr><br> <td align="right" width="100">产品的重量:</td><br> <td><input type="text" name="p_weight" id="p_weight"></td><br> </tr><br> <tr><br> <td align="right" width="100">产品的描述:</td><br> <td><input type="text" name="p_desc" id="p_desc"></td><br> </tr><br> <tr><br> <td align="right" width="100"></td><br> <td><input type="submit" name="submit" value="提交产品数据" onclick="javascript:return check()"></td><br> </tr><br> </table><br> </form><br> </div><br> </body><br></html><br><br>第二个页面:<br> <body><br> <%@ include file="Head.jsp"%><br> <%<br> String p_name = request.getParameter("p_name");<br> double p_price = Double.parseDouble(request.getParameter("p_price"));<br> double p_weight = Double.parseDouble(request.getParameter("p_weight"));<br> String p_desc = request.getParameter("p_desc");<br> out.println(p_name);<br> %><br> </body><br><br>第一个页面输入长笛,第二个页面打印出?¤?? <br>我另外一段代码直接传中文参数就没问题,这个从文本框里取就不行了。求解!!
最佳答案
- 五星知识达人网友:躲不过心动
- 2021-02-06 15:02
第二个页面: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>
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯