jsp常用内置对象---request
request对象,目的是用来获取客户端的请求。
主要方法有:
- String getParameter(String name) //根据表单组件名称获取提交数据
2 <%
3 String name=request.getParameter("name"); 4 String password=request.getParameter("password"); 5 String password1=request.getParameter("password1"); 6 String age=request.getParameter("age"); 7 String email=request.getParameter("email"); 8 String nian=request.getParameter("nian"); 9 String yue=request.getParameter("yue"); 10 String ri=request.getParameter("ri"); 11 %>
- String [ ] getParameterValues(String name) //获取表单组件对应多个值是的请求数据
2 <% 3 // request.setCharacterEncoding("utf-8"); 4 String name=request.getParameter("name"); 5 String password=request.getParameter("passwprd"); 6 //request.getParameterValues("interst");获取表单组件对应多个值是的请求数据 7 String [] channels=request.getParameterValues("interst"); 8 %>
- void serCharacterEncoding(String charset) //解决post提交方式乱码问题
1 <% 2 ////解决post提交方式乱码问题 3 request.setCharacterEncoding("utf-8"); 4 String name=request.getParameter("name"); 5 String password=request.getParameter("passwprd"); 6 String [] channels=request.getParameterValues("interst"); 7 %>
- RequestDidpatcher getRequestDispatcher(String path) //用于转发请求
1 <% 2 String name=request.getParameter("name"); 3 String password=request.getParameter("password"); 4 if(name.equals("sa")&&password.equals("111111")){ 5 RequestDispatcher rd=request.getRequestDispatcher("welcome.jsp"); 6 rd.forward(request,response); 7 }else{ 8 response.sendRedirect("denglu1.jsp"); 9 } 10 %>