服务器端的txt文件在浏览器上显示中文乱码问题处理

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/dakache11/article/details/84748850

如果想让它正常显示,怎么办呢

很简单,只需右键保存,然后用记事本打开就行了,亲测有效

 

 

祝工作顺利,身体健康

展开阅读全文

jsp显示中文乱码问题

12-18

我在jsp页面中通过添加新记录,发现在添加后在显示页面中显示的乱码,不知道为什么?期待高手指点,谢谢!rnrn是在该manastu.jsp页面中显示乱码,代码如下:rn<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>rnrnrn rn 学生管理rnrnrnrnrn<% String id=(String)session.getAttribute("id");rn %>rn rn rn rn 学生管理rnrnrn rnrn 增加学生 rn 返回rnrnrnrn rn学生信息:rn rn rn rn rn 学号rn 姓名rn 密码rn 性别rn 籍贯rn 学院rn 专业rn 修改信息rn 删除学生rnrn<% rn ResultSet rs=stu.getStudent();rn while(rs.next())rn String stu_id=rs.getString("stu_id");rn String stu_name=rs.getString("stu_name");rn String password=rs.getString("password");rn String sex=rs.getString("sex");rn String hometown=rs.getString("hometown");rn String academy=rs.getString("academy");rn String speciality=rs.getString("speciality");rn rnrn%>rn rn <%=stu_id%>rn <%=stu_name%>rn <%=password%>rn <%=sex%>rn <%=hometown%>rn <%=academy%>rn <%=speciality%>rn 修改rn 删除rnrn<%rn rn%>rnrn更新rnrnrn rnrnrnrnrnrnrnservlet studentSer.jsp的代码是:rnrnpackage DBClass;rnrnimport java.io.IOException;rnimport java.sql.ResultSet;rnimport java.sql.SQLException;rnrnimport javax.servlet.RequestDispatcher;rnimport javax.servlet.ServletContext;rnimport javax.servlet.ServletException;rnimport javax.servlet.http.HttpServlet;rnimport javax.servlet.http.HttpServletRequest;rnimport javax.servlet.http.HttpServletResponse;rnrnpublic class studentSer extends HttpServletrn /**rn * rn */rn private static final long serialVersionUID = 1L;rn public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOExceptionrn rn String stu_id=req.getParameter("stu_id");rn String act=req.getParameter("action");rn rn if("delete".equalsIgnoreCase(act))rn tryrn doDelete(stu_id);rn rn res.setContentType("text/html; charset=UTF-8"); rn ServletContext sc = getServletContext(); rn RequestDispatcher rd = sc.getRequestDispatcher("/manastu.jsp"); rn rd.forward(req, res); rn rn catch(Exception e)rn System.out.println("delete studnet wrong!"+e.getMessage());rn rn finallyrn rn if("addStu".equalsIgnoreCase(act))rn tryrn doAdd(req,res,stu_id);rn rn res.setContentType("text/html; charset=UTF-8");rn ServletContext sc=getServletContext();rn RequestDispatcher rd=sc.getRequestDispatcher("/manastu.jsp");rn rd.forward(req, res);rn rn catch(Exception e)rn System.out.println("add studnet wrong!"+e.getMessage());rn rn finallyrn rn if("change".equalsIgnoreCase(act))rn tryrn doNew(req,res,stu_id);rn rn res.setContentType("text/html; charset=UTF-8");rn ServletContext sc=getServletContext();rn RequestDispatcher rd=sc.getRequestDispatcher("/manastu.jsp");rn rd.forward(req,res);rn rn catch(Exception e)rn System.out.println("change studnet wrong!"+e.getMessage());rn rn finallyrn rn if("new".equalsIgnoreCase(act))rn rn res.setContentType("text/html; charset=UTF-8");rn ServletContext sc=getServletContext();rn RequestDispatcher rd=sc.getRequestDispatcher("/manastu.jsp");rn rd.forward(req,res);rn rn rn rn public void doDelete(String stu_id)throws Exceptionrn tryrn stuBean stu=new stuBean();rn stu.delStudent(stu_id);rn catch(Exception e)rn System.out.println("A.dodeletestu wrong!"+e.getMessage());rn rn finallyrn rn public void doNew(HttpServletRequest req,HttpServletResponse res,String stu_id)throws ServletException,IOExceptionrn tryrn String stu_name=(String)req.getParameter("stu_name");rn String password=req.getParameter("password");rn String password1=req.getParameter("password1");rn String password2=req.getParameter("password2");rn String sex=(String)req.getParameter("sex");rn String academy=(String)req.getParameter("academy");rn String speciality=(String)req.getParameter("speciality");rn String hometown=(String)req.getParameter("hometown");rn rn stuBean stu=new stuBean();rn rn stu.setStu_id(stu_id);rn stu.setStu_name(stu_name);rn stu.setSex(sex);rn stu.setAcamedy(academy);rn stu.setHometown(hometown);rn stu.setSpeciality(speciality);rn rn String pas=stu.getPas(stu_id);rn rn if(pas==password)rn if(password1==password2)rn stu.setPassword(password1);rn stu.updateStudent();rn rn elsern res.setContentType("text/html; charset=UTF-8");rn ServletContext sc=getServletContext();rn RequestDispatcher rd=sc.getRequestDispatcher("/changeStuIofo.jsp");rn rd.forward(req,res);rn rn rn rn catch(Exception e)rn System.out.println("A.donewstu wrong!"+e.getMessage());rn rn finallyrn rn rn public void doAdd(HttpServletRequest req,HttpServletResponse res,String stu_id)throws ServletException,IOExceptionrn tryrn String stu_name=(String)req.getParameter("stu_name");rn String password=req.getParameter("password");rn rn String sex=(String)req.getParameter("sex");rn String academy=(String)req.getParameter("academy");rn String speciality=(String)req.getParameter("speciality");rn String hometown=(String)req.getParameter("hometown");rn rn stuBean stu=new stuBean();rn rn stu.setStu_id(stu_id);rn stu.setStu_name(stu_name);rn stu.setPassword(password);rn stu.setSex(sex);rn stu.setAcamedy(academy);rn stu.setHometown(hometown);rn stu.setSpeciality(speciality);rn rn if(iflogin(stu_id)==false) // 如果没注册,增加学生rn stu.addStudent();rn rn elsern String addwrong="对不起,该学生已经存在!";rn req.setAttribute("problem", addwrong);rn res.setContentType("text/html; charset=UTF-8");rn RequestDispatcher rd = getServletContext().getRequestDispatcher("/manastu.jsp");rn rd.forward(req, res);rn rn rn catch(Exception e)rn System.out.println("B.doaddstu wrong!"+e.getMessage());rn rn finallyrn rn rn /**rn * 判断该学生是否已经注册*/rn public boolean iflogin(String stu_id)throws SQLExceptionrn ResultSet rs=null;rn boolean a=false;rn String sql="select * from student where stu_id='"+stu_id+"'";rn tryrn DBBean db=new DBBean();rn rs=db.DBExecute(sql);rn if(rs.next())rn a=true;rn rn else a=false;rn rn catch(Exception e)rn System.out.println("C.there is something wrong!"+e.getMessage());rn rn finallyrn return a;rn rn rnrn rn public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOExceptionrn rn doPost(req,res);rn rnrnrnrnrnrn 论坛

没有更多推荐了,返回首页