Myeclipse里设置了utf-8 jsp也是 html也是
html页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://bbs.itheima.com/forum.php">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="luanma" method="get">
欢迎进入用户注册页面<br/>
姓名:<input type="text" name="name" />
<input type="submit" value="提交" />
</form>
</body>
</html>
servlet:
package com.luanma;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Luanma extends HttpServlet {
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html;charset=utf-8");
resp.setCharacterEncoding("utf-8");
String name = req.getParameter("name");
resp.getWriter().print(name);
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
}
为什么输入了姓名之后,页面返回的是乱码啊 现在做的这个小项目就是,只要在网页上输入的是汉字,储存到数据库里的就是乱码.我的myeclipse oracle 所有的都设置成utf-8了 以前还没乱码,突然就有了
|
|