解決中文無法顯示的問題
1:修改區域設置:在控制面版中選擇區域設置,設爲英語(美國)?nbsp;
然後重起。一切就都正常。
2:在jsp頁中加入一條語句:
<%@ page contentType="text/html;charset=gb2312" %> ?
?sp顯示就正常了。
3:在編譯servlet和jsp時加入代碼選項。編譯servlet使用
javac -encoding iso8859_1 myservlet.java
在jsp的zone配置文件中.修改編譯參數爲:
compiler=builtin-javac -encoding ISO8859_1
使用這種方法後,不需要作其他的改動就可以正常顯示中文了。
4:最土的辦法,在servlet源程序中加入代碼變換語句。如
try{
out.println(new ( (new String("hello world")).getBytes("GBK"),"ISO8859_1"))
}
catch( UnsupportedEncodingException e)
{
.......
}
使用這種方法一定要注意捕獲UnsupportedEncodingException
<?xml:namespace prefix = o />
頁面傳地遞參數
post/get:reguest.getParameter(“name”);
request的方法
字符串函數string
查找:Indexof() lastindexof()
截取:substring
跳轉頁面
window.location.href="logout.jsp"
application.setAttribute(“name”,”lion”); //設置參數
Enumeration data = application.getArributeNames();//取得所有變量的名稱
Data.hasMoreElements()//判斷是否還有變量
Data.nextElement()//取得下一個變量
Application.getAttribute(“name”)//取得變量的值
Config/Out/Page對象
DriverManager類
Class.forName(“org.gjt.mm.mysql.Driver”); //載入MYSQL驅動程式
getConnection(String url, String user, String password) //與數據庫建立連接
getDriver(String url) //打開指定地址的數據庫驅動程式
Cookie類
Cookie classname = new Cookie(String index,String value);//建立Cookie
Response.addCookie(classname); //存儲Cookie
Cookie[] AllCookies = request.getCookies(); //取得所有的Cookie
AllCookies[i].getName(); //取得index
AllCookies[i].getValue();//取得value
class.setMaxAge(Time); //設置Cookie的使用期限
Session類
HttpSession mysession = request.getSession();
mysession.setAttribute("user",username);
String username = (String)mysession.getAttribute("user");
mysession.invalidate();
轉化成漢字
String ToGB2312(String str)
{
Byte GB2312[] = new byte[str.length()];
for(int i=0; i<str.length(); i++)
{
GB2312[i] = (byte)str.charAt(i);
}
return new String(GB2312);
}
Jsp指令<%@taglib uri=”taglibraryURI” prefix=”tagPrefix”%>
//讓用戶使用第三方標籤
<jsp:forward page=”ForwardTo.jsp”>
<jsp:param name=”username” value=”Scott”/>
</jsp:forward>