老师,请问下为什么是乱码的?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | package com.xiaocai.fristservlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class FristServlet extends HttpServlet{ //继承Servlet的父类 //重写Servlet方法 @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //接受客户端发送的请求 String names=request.getParameter( "name" ); String ids=request.getParameter( "id" ); String sexs=request.getParameter( "sex" ); String specs=request.getParameter( "spec" ); String http= "<h1 style='color:red'>!</h1><hr/>" ; //设置编码方式 response.setCharacterEncoding( "UTF-8" ); //返回数据给客户端 PrintWriter out=response.getWriter(); out.println( "<h2>姓名:" +names+ "</h2><hr/>" ); out.println( "<h2>学号:" +ids+ "</h2><hr/>" ); out.println( "<h2>性别:" +sexs+ "</h2><hr/>" ); out.println( "<h2>爱好:" +specs+ "</h2><hr/>" ); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <!DOCTYPE html> < html > < head > < meta charset = "UTF-8" > < title >Insert title here</ title > </ head > < body > < h1 style = "color:red" >学生信息登记</ h1 > < form action = "/JspDemo1/FristServlet" > 姓名:< input type = "text" name = "name" /> <!-- 换行 --> < br />< br /> 学号:< input type = "text" name = "id" /> < br />< br /> 性别: < select > < option value = "sex" >男</ option > < option value = "sex" >女</ option > </ select > < br />< br /> 爱好: < input type = "checkbox" name = "spec" value = "playgame" />玩游戏 < input type = "checkbox" name = "spec" value = "java" />java语言 < input type = "checkbox" name = "spec" value = "shopping" />购物 < input type = "checkbox" name = "spec" value = "s" />唱歌 < br />< br /> < input type = "submit" name = "number" value = "提交" /> </ form > </ body > </ html > |
2
收起
正在回答 回答被采纳积分+1
2回答
qq_Rotation轻描_0
2019-03-27 14:57:36
我就想问下这条问答是哪条
chrismorgen
2019-03-27 14:37:00
你好同学,可以参考一下这条问答,祝学习愉快~
从网页搭建入门Java Web2018版
- 参与学习 人
- 提交作业 1088 份
- 解答问题 10204 个
如果你有Java语言基础,又想以后从事Java Web开发,那么本路径是你的不二选择!本路径从网页搭建开始入手,通过大量案例来学习Java Web基础。定能助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧