易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 :

jsp乱码解决大全(转自csdn一高手)

jsp中文显示乱码解决方案
一、JSP页面显示乱码
二、表单提交中文时出现乱码
三、数据库连接
大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到
的中文乱码的问题及解决办法写出来供大家参考。
一、JSP页面显示乱码
下面的显示页面(display.jsp)就出现乱码:
<html>
<head>
<title>JSP的中文处理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
out.print("JSP的中文处理");
%>
</body>
</html>
对不同的WEB服务器和不同的JDK版本,处理结果就不一样。原因:服务器使用的编码方式不同和浏览器
对不同的字符显示结果不同而导致的。解决办法:在JSP页面中指定编码方式(gb2312),即在页面的第一
行加上:<%@ page contentType="text/html; charset=gb2312"%>,就可以消除乱码了。完整页面如下

<%@ page contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>JSP的中文处理</title>
<meta http-equiv="C ......

jsp/get/set/struts.xml存取

get
jsp         url          ${param.serialID}
action    jsp          String commentId = ServletActionContext.getRequest().getParameter("commentId");
---------------------------------------
action    ServletActionContext.getRequest().setAttribute("searchContent", searchContent);
jsp         action      <s:property value="searchContent"></s:property>
---------------------------------------
function hanshu(num)
{
    window.location.href="<%=request.getContextPath()%>/a.action?num="+num;
}
<a href="javascript:hanshu('${param.url参数名}')"></a>
=====================
post
//使用trim()
String.prototype.trim=function()
{
   return this.replace(/(^\s*)|(\s*$)/g, "");
}
function hanshu()
{
......

jsp/get/set/struts.xml存取

get
jsp         url          ${param.serialID}
action    jsp          String commentId = ServletActionContext.getRequest().getParameter("commentId");
---------------------------------------
action    ServletActionContext.getRequest().setAttribute("searchContent", searchContent);
jsp         action      <s:property value="searchContent"></s:property>
---------------------------------------
function hanshu(num)
{
    window.location.href="<%=request.getContextPath()%>/a.action?num="+num;
}
<a href="javascript:hanshu('${param.url参数名}')"></a>
=====================
post
//使用trim()
String.prototype.trim=function()
{
   return this.replace(/(^\s*)|(\s*$)/g, "");
}
function hanshu()
{
......

将jsp页面中table导出到doc

<SCRIPT LANGUAGE="javascript">
       //指定页面区域内容导入Word
       function AllAreaWord() {
       var oWD = new ActiveXObject("Word.Application");
       var oDC = oWD.Documents.Add("",0,1);
       var oRange =oDC.Range(0,1);
       var sel = document.body.createTextRange();
       sel.moveToElementText(PrintA);
       sel.select();
       sel.execCommand("Copy");
       oRange.Paste();
       oWD.Application.Visible = true;
       //window.close();
       }
</SCRIPT>
应用举例:
<table width="100%" align=center border="0" cellpadding="0" cellspacing="0" id = "PrintA" ......

组拼jsp方法

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> ......

组拼jsp方法2

<html:html>
<HEAD>
<tiles:insert attribute="header" />
</HEAD>
<body>
<tiles:insert attribute="top" />
<table width="100%" height="400" border="0" align="center"
 cellpadding="0" cellspacing="0">
 <tr>
  <td width="178" height="450" valign="top" class="gray" id="mtd"><!--left start-->
  <tiles:insert attribute="menu" /> <!--left end--></td>
  <td width="1" class="gray1"></td>
  <td valign="top" width="99%" class="mainTableContent"><!--main start--> <tiles:insert attribute="main" /> <!--main end-->
  <br>
  </td>
 </tr>
</table> ......

组拼jsp方法3

<table width=100% border="0" align="center" cellpadding="0"
 cellspacing="0">
 <tr>
  <td height="1" class="gray1"></td>
 </tr>
</table>
<tiles:insert attribute="footer" />
</body>
</html:html> ......
总记录数:40319; 总页数:6720; 每页6 条; 首页 上一页 [1784] [1785] [1786] [1787] 1788 [1789] [1790] [1791] [1792] [1793]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号