JSP数据交互(一)
来源:互联网 发布:linux yum安装ant 编辑:程序博客网 时间:2024/06/05 07:09
01.内置对象:不需要做任何声明就可以直接使用的对象。 JSP九大内置对象: request 请求对象 out 输出对象 response 响应对象 application 应用程序对象 session 会话对象 pageContext 页面上下文对象 page 页面对象 config 配置对象 execption 异常对象02.request对象的常用方法:request.getParameter(String name) 获取表单提交的元素request.getParameterValues(String name) 获取表单提交的一堆数据request.setCharacterEncoding(String charst) 解决乱码问题request.getRequestDispachert(String Path).forward(request,response) 转发请求request.getRemoteAddr() 获取提交数据电脑的IP03,解决乱码的方法: post提交方法: 3-01,request.setCharacterEncoding("utf-8"); get提交方法: 3-02,String name=request.getParameter("name"); name =new String(name.getBytes("ISO-8859-1"),"UTF-8"); 3-03,找到Tomcat目录结构\conf\server.xml文件,在<Connector>元素中添加URIEncoding属性,值为"UTF-8"; URIEncoding="UTF-8"04:示例: <title>表单页面</title> </head> <body> <form action="do.jsp" method="post"> 姓名:<input type="text" name="txtname" value="<%=request.getAttribute("name")%>"/> 密码:<input type="password" name="txtpwd"/> 爱好:<input type="checkbox" name="hobby"/>篮球 <input type="checkbox" name="hobby"/>慢跑 <input type="submit" value="提交"/> </form> </body> <title>处理页面</title> </head> <body> <% request.setCharacterEncoding("utf-8"); String name=request.getParameter("txtname"); String pwd=request.getParameter("txtpwd"); String [] hobby=request.getParameterValues("hobby"); if(name.equals("科比")&&pwd.equals("666")){ request.setAttribute("name",name); request.setAttribute("hobby", hobby); request.getRequestDispatcher("/success.jsp").forward(request, response); }else{ request.setAttribute("name",name); request.getRequestDispatcher("/index.jsp").forward(request, response); } %> </body></html> <title>成功页面</title> </head> <body> 欢迎你--<%=request.getAttribute("name") %> <%=request.getAttribute("hobby") %> </body></html>
0 0
- JSP数据交互(一)
- JSP数据交互(一)
- JSP数据交互(一)
- jsp数据交互(一)
- JSP数据交互(一)
- JSP数据交互(一)
- JSP数据交互(一)
- JSP数据交互(一)
- JSP数据交互(一)
- jsp数据交互(一)
- JSP数据交互(一)
- 【jsp/servlet】jsp数据交互(一)
- JSP数据交互(一)补充
- s2jsp第二章 jsp数据交互(一)
- js jsp 数据交互
- JSP数据交互
- JSP数据交互
- jsp数据交互(二)
- POJ,3713 Transferring Sylla
- UVa 122 (紫书)
- 在TI提供的USB dongle 到底是什么?
- JVM学习:垃圾回收器学习(1)——认识垃圾回收器
- Spring 拦截器的使用
- JSP数据交互(一)
- Linux 信号之mysleep
- Android进程的内存管理分析
- javascript篇三dom解析html
- python 读写文件包含多种编码格式
- java的static语句块,普通语句块,构造函数
- Zip文件压缩与解压
- BZOJ 1070: [SCOI2007]修车
- python查看是32位还是64位版本