老玉米:
有点烦晕,jsp德中文乱码问题。改成这样就没有乱码了
[阅读: 674] 2006-09-27 02:32:11
<%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="java.util.ArrayList" %>
<%!
public String getStr(String str){
try{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e){
return "";
}
}
%>
<html>
<head><title>View Session JSP </title></head>
<body>
<h2>Session Info From A JSP</h2>
<%
out.println("sessionid: " + session.getId() + "<br>");
ArrayList<String> strs = (ArrayList<String>)session.getAttribute("strs");
if (strs == null){
strs = new ArrayList<String>();
session.setAttribute("strs",strs);
}
String str = request.getParameter("str");
if (str != null){
strs.add(str);
}
for (int i=0; i<strs.size(); i++){
out.println("<label>" + getStr(strs.get(i)) + "</label><br>");
}
%>
<form action="test.jsp" method="POST">
<h3>输入</h3> <input type="text" name="str"><br>
<input type="submit" value="提交"><br>
</form>
</body>
</html>