编码URLEncoder
解码URLDecoder
public class UrlDemo extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String Love = "我爱蓉蓉,蓉蓉爱我!";
//编码解码过程。URL的方法
//编码
String E_Love = URLEncoder.encode(Love, "UTF-8");
System.out.println(E_Love);
//解码
String D_Love = URLDecoder.decode(E_Love, "UTF-8");
System.out.println(D_Love);
}
- 服务器行为 : / 执行路径:当前项目的根目录
- 浏览器行为 : / 执行路:站点:tomcat安装目录中的一个webapps目录: 存放很多的网站 (web工程)
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
/**
* 重定向:浏览器行为(进一步请求302+location)
*/
response.sendRedirect("/Develop_Servlet_Cookie/hello.html");
/**
* 请求转发:服务器行为(执行当前项目的根目录)
*/
request.getRequestDispatcher("/hello.html").forward(request, response);
/**
* 超链接标签:浏览器行为
*/
response.getWriter().write("<a href='/Develop_Servlet_Cookie/hello.html'>超链接</a>");
//href=/Develop_Servlet_Cookie --->优化:上下文路径
//灵活
response.getWriter().write("<a href='"+request.getContextPath()+"/hello.html'>超链接</a>");
/**
* 表单提交数据的时候,action="资源文件地址"
* 浏览器行为
*/
response.getWriter().write("<form actiom='/Develop_Servlet_Cookie/hello.html' method='post'><input type='submit' value='提交' /></form>");