servlet中读写中文的办法
来源:互联网 发布:javac java heap space 编辑:程序博客网 时间:2024/06/05 04:32
网页部分:
<html>
<body bgcolor="pink">
<center>
<form method="post" action=http://127.0.0.1:8000/Gift/Gift>
<table>
<tr>
<td>Enter Login Name:</td>
<td><input type="text" name="loginid"></td>
</tr>
<tr>
<td>Enter password:</td>
<td><input type="password" name="passwd"></td>
</tr>
</table>
<input type="submit" value="submit">
</form>
</center>
</body>
</html>
Servlet部分:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class GiftServlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res) throws IOException
{
boolean cookieFound = false;
Cookie myCookie = null;
Cookie[] cookieset = req.getCookies();
res.setContentType("text/html;charset=gb2312");
PrintWriter pw = res.getWriter();
pw.println("<html>");
pw.println("<body>");
pw.println("这里是河北软件职业技术学院");
pw.println("<br>");
req.setCharacterEncoding("gb2312");
pw.println("你好:" + req.getParameter("loginid"));
if(cookieset != null)
{
for(int i = 0;i < cookieset.length;i++)
{
if(cookieset[i].getName().equals("logincount"))
{
myCookie = cookieset[i];
cookieFound = true;
}
}
}
if(cookieFound)
{
int temp = Integer.parseInt(myCookie.getValue());
temp ++;
pw.println("Congratulations!!!!!!!!, a gift is waiting you");
pw.println("The number of times you have logged in is " + String.valueOf(temp));
myCookie.setValue(String.valueOf(temp));
int age = 60*60*24*30;
myCookie.setMaxAge(age);
res.addCookie(myCookie);
cookieFound = false;
}
else
{
int temp = 1;
pw.println("This is the first time you have logged on to the server");
myCookie = new Cookie("logincount",String.valueOf(temp));
int age = 60*60*24;
myCookie.setMaxAge(age);
res.addCookie(myCookie);
}
pw.println("</body>");
pw.println("</html>");
}
}
- servlet中读写中文的办法
- java ---servlet解决中文乱码的几种办法
- Mysql 中不支持中文的办法
- 链接中存在中文的处理办法
- Ajax + jsp +servlet 中文乱码问题解决办法
- python中mysql中文的读写
- servlet中中文乱码问题的解决
- 解决servlet中中文乱码的方法
- Servlet中解决中文乱码的方法
- Servlet中解决中文乱码的方法
- Servlet中解决中文乱码的方法
- 解决Servlet中,中文乱码的问题
- QTE中中文显示问题的解决的办法
- servlet得到IP的办法
- 缺少servlet-api的办法
- CXgrid incsearch中无法查找中文的办法
- 往MySql中插入中文的乱码问题解决办法
- delphi 中 Label 中文显示不全的问题解决办法
- Winpcap学习第二天
- WAP
- 彩信业务常见问题
- SMS,EMS,MMS
- C#常用函数和方法集汇总
- servlet中读写中文的办法
- 硬盘安装Fedora Core 5实录
- jdbc连接各种数据库方式列表
- 设计模式之Prototype
- Xml WebService完全实例解析(一)
- profile参数详解
- Java性能优化技巧集锦
- 微软的收购策略
- 截取双字节字符串