package star.july;
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;
/**
* 路径问题(如何正确写出文件路径)
* 1.首先在每个路径加一个/
* 2.分清楚是服务器行为还是浏览器行为
* 服务器行为:应用内的,在Web-INF的(范围小)
* 浏览器行为:在tomcat的webapps目录下的(范围大)
* @author Starjuly
*
*/
public class PathDemo extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//服务器行为
//转发
request.getRequestDispatcher("/index.jsp").forward(request,response);
//定位路径
this.getServletContext().getRealPath("/index.jsp");
this.getServletContext().getResourcePaths("/index.jsp");
//浏览器行为
//重定向
response.sendRedirect("/day10/index.jsp");
//链接
//<a href="/day10/index.jsp">
//表单提交
//<form action = "/day10/index.jsp">
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
路径问题(如何正确写出文件路径)
最新推荐文章于 2024-03-15 18:07:05 发布