request对象和response对象(13)
来源:未知 责任编辑:责任编辑 发表时间:2014-05-10 12:18 点击:次
p> <td colspan="2">
p> <input type="submit" value="注册" />
p> </td>
p> </tr>
p> </table>
p> </form>
p> </body>
p></html>
p>复制代码
p>复制代码
p>package cn.lsl.request;
p>
p>import java.io.IOException;
p>import java.net.URLDecoder;
p>import java.net.URLEncoder;
p>import java.util.Arrays;
p>import java.util.Enumeration;
p>import java.util.Map;
p>import java.util.Set;
p>
p>import javax.activation.URLDataSource;
p>import javax.servlet.ServletException;
p>import javax.servlet.http.HttpServlet;
p>import javax.servlet.http.HttpServletRequest;
p>import javax.servlet.http.HttpServletResponse;
p>
p>public class RequestDemo5 extends HttpServlet {
p>
p> public void doGet(HttpServletRequest request, HttpServletResponse response)
p> throws ServletException, IOException {
p> //解决post乱码
p> request.setCharacterEncoding("utf-8");
p>
p>
p>
p>
p> //通过getParameter获得指定数据
p> String username = request.getParameter("username");
p> System.out.println(username);
p>
p> //解决get乱码
p>// username = URLEncoder.encode(username, "ISO-8859-1"); //用ISO-8859-1编码
p>// username = URLDecoder.decode(username, "utf-8"); //用utf-8解码
p>
p>
p>// username = new String(username.getBytes("ISO-8859-1"),"UTF-8");
p>
p>// System.out.println(username);
p>
p>
p>
p> String gender = request.getParameter("gender");
p> System.out.println(gender);
p>
p> //获取checkbox所有提交数据 --- getParameterValues
p> String[] hobbies = request.getParameterValues("hobby");
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>