路径问题(如何正确写出文件路径)
生活随笔
收集整理的這篇文章主要介紹了
路径问题(如何正确写出文件路径)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
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);}}
總結
以上是生活随笔為你收集整理的路径问题(如何正确写出文件路径)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html页面提交数据,利用servlet
- 下一篇: 利用cookie显示上次浏览的时间