我写的
package com;import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.SimpleDateFormat;public class DateServlet extends HttpServlet { public void init(ServletConfig config) throws ServletException {
super.init(config);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html; charset=GB2312");
response.setCharacterEncoding("GB2312");
out.print("<html>");
out.print("<body>");
response.setHeader("Refresh", "2");
out.print("Now Time:");
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
String dateString = formatter.format(currentTime); out.println("<br>" + dateString);
String Uname = "返回";
String naString=new String(Uname.getBytes("GBK"),"GB2312");
out.println("<a href='servlet.jsp'>" + naString + "</a>");
out
.print("<h3>九九乘法口诀表</h3>"
+ "<table width='90%' border='1' align='center' cellpadding='0' cellspacing='1' id='Table1'>"
+ "<tr bgcolor='#E6E6E6'>" + "<th>1</th>"
+ "<th>2</th>" + "<th>3</th>" + "<th>4</th>"
+ "<th>5</th>" + "<th>6</th>" + "<th>7</th>"
+ "<th>8</th>" + "<th>9</th>" + "</tr>");
for (int i = 1; i <= 9; i++) {
out.print("<tr>");
for (int j = 1; j <= i; j++) {
out.print("<td bgcolor='#CCCCCC' align='center'>");
out.print(i);
out.print("*");
out.print(j);
out.print("=");
out.print(i * j);
}
out.print("</tr>");
}
Counter counter = new Counter();
String cou = String.valueOf(counter);
out.print(cou);
out.print("</table>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
把你那个Uname 的String输到网叶上就成????了
package com;import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.text.SimpleDateFormat;public class DateServlet extends HttpServlet { public void init(ServletConfig config) throws ServletException {
super.init(config);
} public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
} public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
response.setContentType("text/html; charset=GB2312");
response.setCharacterEncoding("GB2312");
out.print("<html>");
out.print("<body>");
response.setHeader("Refresh", "2");
out.print("Now Time:");
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm:ss");
String dateString = formatter.format(currentTime); out.println("<br>" + dateString);
String Uname = "返回";
String naString=new String(Uname.getBytes("GBK"),"GB2312");
out.println("<a href='servlet.jsp'>" + naString + "</a>");
out
.print("<h3>九九乘法口诀表</h3>"
+ "<table width='90%' border='1' align='center' cellpadding='0' cellspacing='1' id='Table1'>"
+ "<tr bgcolor='#E6E6E6'>" + "<th>1</th>"
+ "<th>2</th>" + "<th>3</th>" + "<th>4</th>"
+ "<th>5</th>" + "<th>6</th>" + "<th>7</th>"
+ "<th>8</th>" + "<th>9</th>" + "</tr>");
for (int i = 1; i <= 9; i++) {
out.print("<tr>");
for (int j = 1; j <= i; j++) {
out.print("<td bgcolor='#CCCCCC' align='center'>");
out.print(i);
out.print("*");
out.print(j);
out.print("=");
out.print(i * j);
}
out.print("</tr>");
}
Counter counter = new Counter();
String cou = String.valueOf(counter);
out.print(cou);
out.print("</table>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
把你那个Uname 的String输到网叶上就成????了
解决方案 »
- google密钥被抢注
- J2EE和J2ME的区别
- 用户名,手机等不能重复是放在一个方法里面处理还是分别处理?
- 高分求struts2 doubleselect 标签级联问题
- 麻烦问题,看各位有什么妙招!
- 新人求助,怎么用超链接传送变量啊~~~~
- javamail问题: 该段程序无法发送给Hotmail的用户
- JBoss Servlet+JSP+Hibernate 出错有人见过这错误信息?
- struts绝对不如webwork2
- 在JBOSS中部署实体BEAN,如何设置Bean的属性字段的默认值?
- Child count should be a multiple of the columns attribute?
- 急求~~如何实现域外用户登陆WEB应用弹出域登陆框
这个地方乱码?
不用Uname.getBytes("GBK")呀,系统用默认方式编码的,这样你得到的是GBK的byte array,然后你对GBK的byte array去构造gb2312的string,肯定会乱码呀
throws ServletException, IOException {
request.setCharacterEncoding("GB2312"); //加上这句
fuyou001说的很好
response.setContentType("text/html; charset=GB2312");
response.setCharacterEncoding("GB2312");
如果不行就配过滤器,过滤器是处理乱码的主要方法,当用了过滤器仍有乱码,我們才通常采取其它方法来解决,你这种应该用过滤器才能解决像这种request.setCharacterEncoding("GB2312");
String naString=new String(Uname.getBytes("iso-8859-1"),"GB2312");
String naString = URLDecoder.decode("返回","GB2312");
这些都处理请求的乱码而不是输出,希望不要乱用
response.setContentType("text/html; charset=GB2312");
response.setCharacterEncoding("GB2312");
PrintWriter out = response.getWriter();