package cn.edu.url;
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;
//训练写地址的规范性,WEB工程中各类地址的写法
public class ServletDemo1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//写任何一个地址最好用“/”开头,如果这个地址是给服务器用的,那么“/”代表的是当前WEB应用
//如果这个地址是给浏览器用的,那么“/”代表的是网站
//要写地址常用的语句
//1.“/”代表整个WEB应用
request.getRequestDispatcher("/form1.html").forward(request, response);
//2.“/”代表一个网站
response.sendRedirect("/day06/form1.html");
//3.“/”代表整个WEB应用
this.getServletContext().getRealPath("/form1.html");
//4.“/”代表整个WEB应用
this.getServletContext().getResourceAsStream("/public/foot.jsp");
//5.“/”代表一个网站
/*
* <a href="/day06/form1.html">点点</a>
*
* <form action="/day06/form1.html>
* </form>
* */
//想获取URL资源,用“/”,想获取硬盘上的资源就用“\”(如C:\WEB-INF\MyNet)
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}