JSP页面要写上 encoding = gbk
解决方案 »
- jsp页面中无法使用EL表达式
- struts.xml在myeclipse8.5下正常,但在myeclipse9下就有语法错误
- 如何调用远程的web service
- 在Win2003下Tomcat的問題?
- 放分了啊,很菜了的问题
- 菜问:HttpServletRequest.getQueryString()的作用是什么?
- 菜鸟问题,请问如何在win2000中安装jsp的运行环境,如何配置?
- 谁知道哪有Jbuilder8的Crack文件,高分相赠!
- 程序升级为spring4+hibernate4+struts2以后,不识别DelegatingRequestProcessor了
- ajax轮询内部的参数刷新问题
- JSP文件怎么运行啊
- 如何跳回前2级浏览的页面?
如果你只是写jsp的话就写在jsp页面里,但是要向上写,不要在你要输出的语句下面写。
如果写MVC模式的话就写在servlet里。肯定好用
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/cms.tld" prefix="cms" %>
<%@ page contentType="text/html;charset=gb2312" %>
<%@ page import="java.util.Map" %>
<%@ page import="cms.admin.control.CheckPermission" %>
<%@ page errorPage="../errorPage.jsp" %><% if (session.getAttribute("user")==null) throw new Exception("session is not loaded,please logon!");
CheckPermission cp=new CheckPermission();
if (!(cp.isPermission((Integer)(((Map)session.getAttribute("user")).get("user_num")),"editoroptions.do")))
throw new Exception("Sorry, you do not have permission to access this page!");
%><html:html>
<head>
<title>search and edit and assign</title></head><script language="JavaScript">
function toassign(){
document.all["actionTag"].value ="1";
document.all["EditAssignAllToTranslateForm"].submit();
}
function todel(){
document.all["actionTag"].value ="2";
document.all["EditAssignAllToTranslateForm"].submit();
}
function toviewassign(){
document.all["actionTag"].value ="3";
document.all["EditAssignAllToTranslateForm"].submit();
}
</script><BODY>
<table border="1" width="90%" align="center">
<tr>
<logic:iterate id="link" name="linkproductline">
<td><a href="./editallpage.do?product_id=<bean:write name="link" property="product_id"/>"><bean:write name="link" property="product_name"/></td>
</logic:iterate>
<td><a href="./editoroptions.do">section page</a></td>
<td><a href="./options.do">main page</a></td>
</tr>
</table>
<hr>
<p>You are in <font color="#FF0000"><b><%=(String)request.getAttribute("product_id")%></b></font>line</p>
<font color="#FF0000"><b><html:errors/></b></font><%if ((String)request.getAttribute("prompt")!=null){%>
<font color="#FF0000"><b><%=(String)request.getAttribute("prompt")%></b></font>
<%}%>
<html:form action="/assignalltotranslate">
<input type="hidden" name="actionTag">
<input type="hidden" name="product_id" value="<%=(String)request.getAttribute("product_id")%>">
<p> choose a translator:<cms:userListTag name="editUserNum" value="<%=(String)request.getAttribute("usernum")%>" /></p>
<p>the search result:<%=request.getAttribute("fromend")%></p>
<p>
<table border="1" width="100%" id="table1">
<tr>
<td>checkSel</td><td>itme_num</td><td width="20%">title</td><td>edit_user</td><td>date_of_entry</td><td>category</td><td>status</td><td>product line</td><td>back to editor reason</td>
</tr><logic:iterate id="result" name="resulteditsearch">
<tr>
<td><input type="checkbox" name="processed_num" value="<bean:write name="result" property="processed_num"/>"></td>
<td>
<a href="./editpage.do?processed_num=<bean:write name='result' property='processed_num'/>"><bean:write name="result" property="processed_num"/></a></td>
<td width="20%"><a href="./editpage.do?processed_num=<bean:write name='result' property='processed_num'/>"><bean:write name="result" property="subject"/></a></td>
<td><bean:write name="result" property="user_id"/></td>
<td><bean:write name="result" property="entry_date"/></td>
<td><bean:write name="result" property="category"/></td>
<td><bean:write name="result" property="status_id"/></td>
<td><bean:write name="result" property="productid"/></td>
<td><bean:write name="result" property="reason"/></td>
</tr>
</logic:iterate></table>
<p>
<input type=button value="assign to translator" onclick="toassign();"><input type=button value="delete" onclick="todel();"><input type=button value="view articles assigned to transltor" onclick="toviewassign();">
</p></html:form>
</body>
</html:html>
比如要获取另一个页面提交过来的信息。
String '课程名'= new String(request.getParameter("'课程名'").getBytes("iso-8859-1"));
你再看一下你想获取的变量,用这个应该可以解决,你试一下。
<html:html>
改为:
<html:html local="true">
显示的中文是乱码呢?要是这样,可能是数据库中文乱码。
{
try
{
if(action==null)
{
action ="";
}
byte[] b =action.getBytes("ISO8859_1");
String convert =new String(b,"GBK");
return convert;
}
catch(Exception e)
{
System.out.println("GBK Exception:"+e);
}
return " ";
}
<%@ page contentType="text/html;charset=GB2312" %>2.servlet中从request中取得string时转一下:
String name=request.getParameter("username");
name=new String(name.getBytes("ISO8859_1"))3.连接mysql时写成如此:
jdbc:mysql://192.168.3.235:3306/no2?useUnicode=true&characterEncoding=GB2312
1、使用如下命令生成对应的文件 native2ascii -encoding gb2312 ApplicationResources_xx.properties ApplicationResources_zh.properties
2、在JSP文件中做如下设置:
1、<%@ page language="java" contentType="text/html; charset=utf-8"%> 一定是:utf-8
2、<html:html locale="true">3、好像在eclipse中不好直接写很多的属性文件,建议打开对应的文件夹后,用记事本工具一个个的写较好。
如果是在JSP页面中的连接数据库的话,只要把获取的值做一下转换就行了,
当然,要先写<%@ page contentType="text/html;charset=GB2312" %>
要是可以在<head></head>中也写上一个<meta>,在其中写上contentType="text/html;charset=GB2312" 这个属性。我想用jsp连接数据库应该没什么问题吧。
在servlet 中。