当前位置: 首页 > news >正文

佛山 网址开发 网站制作培训学做网站要多久

佛山 网址开发 网站制作,培训学做网站要多久,免费模板下载免费版,网站设计公司收费标准1.相对路径 不以/开头 以当前资源的所在路径为出发点去找目标资源 语法: ./表示当前资源的路径 ../表示当前资源的上一层路径 缺点:不同位置,相对路径写法不同2.绝对路径 以固定的路径作为出发点作为目标资源,和当前资源所在路径没关系 语法:以/开头,不同的项目中,固定的路径…1.相对路径 不以/开头 以当前资源的所在路径为出发点去找目标资源 语法:    ./表示当前资源的路径 ../表示当前资源的上一层路径 缺点:不同位置,相对路径写法不同2.绝对路径 以固定的路径作为出发点作为目标资源,和当前资源所在路径没关系 语法:以/开头,不同的项目中,固定的路径的出发点可能不一致,我的浏览器以http://localhost:8080为出发点 缺点:需要补充项目上下文,项目上下文会发生改变在不同html文件中访问photo.png图片 index.html文件 img路径相对路径写法 !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body img srcstatic/img/photo.png/ /body/html 当前资源的请求路径:http://localhost:8080/demo05_path_war_exploded/index.html 当前资源是:index.html 当前资源的所在路径是:http://localhost:8080/demo05_path_war_exploded/ 相对路径的规则就是当前资源的所在路径后拼接目标资源 浏览器向服务器请求http://localhost:8080/demo05_path_war_exploded/static/img/photo.png test.html文件 !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body img src../../../static/img/photo.png/ /body /html当前资源的请求路径:http://localhost:8080/demo05_path_war_exploded/a/b/c/test.html 当前资源是:test.htm 当前资源的所在路径是:http://localhost:8080/demo05_path_war_exploded/a/b/c/ 相对路径的规则就是当前资源的所在路径后拼接目标资源 浏览器向服务器请求 http://localhost:8080/demo05_path_war_exploded/a/b/c/../../../static/img/photo.png http://localhost:8080/demo05_path_war_exploded/static/img/photo.png view.html文件无法直接访问,使用请求转发 View1Servletpackage com.yan.servlet;import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse;import java.io.IOException; WebServlet(/View1Servlet) public class View1Servlet extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req.getRequestDispatcher(WEB-INF/views/view.html).forward(req,resp);//请求转发} } view.html文件 !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body img src../../static/img/photo.png/ /body /html 当前资源的请求路径:http://localhost:8080/demo05_path_war_exploded/View1Servlet 当前资源是:View1Servlet 当前资源的所在路径是:http://localhost:8080/demo05_path_war_exploded/ 相对路径的规则就是当前资源的所在路径后拼接目标资源 浏览器向服务器请求 http://localhost:8080/demo05_path_war_exploded/../../static/img/photo.png http://localhost:8080/static/img/photo.png 无法找到图片 正确代码: !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body img srcstatic/img/photo.png/ /body /html 当前资源的请求路径:http://localhost:8080/demo05_path_war_exploded/View1Servlet 当前资源是:View1Servlet 当前资源的所在路径是:http://localhost:8080/demo05_path_war_exploded/ 相对路径的规则就是当前资源的所在路径后拼接目标资源 浏览器向服务器请求 http://localhost:8080/demo05_path_war_exploded/static/img/photo.png可以找到图片 绝对路径 绝对路径 以固定的路径作为出发点作为目标资源,和当前资源所在路径没关系 语法:以/开头,不同的项目中,固定的路径的出发点可能不一致,我的浏览器以http://localhost:8080为出发点 缺点:需要补充项目上下文,项目上下文会发生改变 index.html文件  !DOCTYPE html html langen headmeta charsetUTF-8titleTitle/title /head body img src/demo05_path_war_exploded/static/img/photo.png/ /body/html 通过head标签中的base标签可以把所有不加修饰的相对路径加上href定义的公共前缀变为绝对路径 headmeta charsetUTF-8titleTitle/titlebase href/demo05_path_war_exploded/ /head 重定向的路径问题 例1:  Servlet01  WebServlet(/Servlet01) public class Servlet01 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.sendRedirect(Servlet02);//重定向} } Servlet02 WebServlet(/Servlet02) public class Servlet02 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println(Servlet02执行了);} }当前资源的请求路径:http://localhost:8080/demo05_path_war_exploded/Servlet01 当前资源是:Servlet1 当前资源的所在路径是:http://localhost:8080/demo05_path_war_exploded/ 重定向使用相对路径写法 resp.sendRedirect(Servlet02);//重定向 浏览器响应:看Location 浏览器向服务器请求 ttp://localhost:8080/demo05_path_war_exploded/Servlet02 例二: servlet01 WebServlet(/x/y/z/Servlet01) public class Servlet01 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.sendRedirect(../../../Servlet02);} } servlet02 WebServlet(/Servlet02) public class Servlet02 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println(Servlet02执行了); 当前资源的请求路径:http://localhost:8080/demo05_path_war_exploded/x/y/z/Servlet01 当前资源是:Servlet01 当前资源的所在路径是:http://localhost:8080/demo05_path_war_exploded/ 重定向使用相对路径写法 resp.sendRedirect(../../../Servlet02);//重定向 浏览器响应:看Location 浏览器向服务器请求 ttp://localhost:8080/demo05_path_war_exploded/x/y/z/../../../Servlet02 ttp://localhost:8080/demo05_path_war_exploded/Servlet02 总结:相对路径规则和前端相对路径一致 例三: 绝对路径重定向: Servlet01: WebServlet(/x/y/z/Servlet01) public class Servlet01 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {resp.sendRedirect(/demo05_path_war_exploded/Servlet02);} }Servlet02:  WebServlet(/Servlet02) public class Servlet02 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println(Servlet02执行了);} } 以下代码得到绝对路径更灵活 ServletContext servletContext req.getServletContext(); String contextPath servletContext.getContextPath();//返回项目的上下文路径 resp.sendRedirect(contextPath/servlet02); 绝对路径以http://localhost:8080为出发点 浏览器向服务器请求 ttp://localhost:8080/demo05_path_war_exploded/Servlet02 请求转发的路径问题 例1: 请求转发的相对路径写法: Servlet01: WebServlet(/Servlet01) public class Servlet01 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {req.getRequestDispatcher(Servlet02).forward(req,resp);//相对路径写法} } Servlet02: WebServlet(/Servlet02) public class Servlet02 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println(Servlet02执行了);} }例2: 请求转发的绝对路径写法,不需要写上下文 Servlet01 WebServlet(/Servlet01) public class Servlet01 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//绝对路径写法不需要添加项目上下文//请求转发的/代表 项目上下文req.getRequestDispatcher(/Servlet02).forward(req,resp);} } Servlet02 WebServlet(/Servlet02) public class Servlet02 extends HttpServlet {Overrideprotected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {System.out.println(Servlet02执行了);} } 不设置项目上下文 在idea 的编辑配置-部署中将应用程序上下文 改为/ 好处:原来/demo05_path_war_exploded/Servlet02的绝对路径写法,现在写为/Servlet02
http://www.hkea.cn/news/14407178/

相关文章:

  • 网站建设免费代理wordpress 开玩笑 呵
  • 自己建网站装饰公司网站建设流程
  • 自适应网站的缺点广州网站建设排行
  • 小程序开发 与网站开发区别ps切片做网站
  • 网站程序组成现在做什么网站好
  • wordpress创建数据库类型选什么用做网站不带优化的吗
  • 企业网站开发常用的字体网站怎么做关键词排名
  • 网站建设公司的网销好做吗二手车网站建设论文
  • wordpress ie8不兼容青岛市做网站优化
  • 电子商务网站开发技术路线山西建站公司
  • 网站托管内容网站优化公司排行
  • 网站模板套餐深圳画册设计企业
  • 怎么注册公司抖音账号西安seo公司哪家好
  • 电子商务网站建设的一般步骤有论企业网站建设的必要性
  • 如何使用c 进行网站开发上海seo推广服务
  • 黑龙江建设部网站四川电商推广公司
  • 网站如何快速被百度收录wordpress分类目录样式
  • 个人网站导航html源码江西专业网站建设
  • 安徽网站线上开发公司开发app贵吗
  • 国内永久免费saascrm做网站送优化
  • 做视频比较好的理财网站有哪些服装外贸流程
  • 网站免费建站pixiv app秀米网站怎么做推文
  • 做网站赚金币专注小程序定制开发
  • 西部数码怎么上传网站淮安市住房和城乡建设局网站首页
  • 企业网站一般包括哪些内容青岛网站建设公司哪家好
  • 东莞有哪些做网站网站不备案不能访问吗
  • nike网站建设分析百度平台商家
  • 国外电商网站有哪些网站开发 荣誉资质
  • 文山 砚山 网站建设ps做图 游戏下载网站
  • 网站开发是打代码吗品牌创建的六个步骤