首页 > Web开发 > 详细

html-base标签

时间:2020-09-11 10:04:48      阅读:57      评论:0      收藏:0      [点我收藏+]

问题引入

页面二使用a标签请求转发方式跳转页面一,

页面一再使用a标签相对路径的跳转方式跳转到页面二就会出错。

技术分享图片

 

 

解决方法:使用base标签

<!-- base标签设置页面相对路径工作时参照的地址
   herf属性就是参数的地址值
   -->
<base href="http://localhost:8088/HtmlBase_war_exploded/a/b/c.html">

相关代码

技术分享图片
package com.orz;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * @author orz
 * @create 2020-09-10 23:00
 */
public class ForwardC extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.getRequestDispatcher("/a/b/c.html").forward(req,resp);
    }
}
View Code
技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>这是首页</title>

</head>
<body>
<p>这是web下的index首页</p>
<a href="a/b/c.html">a/b/c.html</a><br/>
<a href="http://localhost:8088/HtmlBase_war_exploded/forwardC">请求转发到a/b/c.html</a>
</body>
</html>
View Code
技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!-- base标签设置页面相对路径工作时参照的地址
       herf属性就是参数的地址值
       -->
    <base href="http://localhost:8088/HtmlBase_war_exploded/a/b/c.html">
</head>
<body>
<p>这是a下的b下的c</p>
<a href="../../index.html">返回首页</a>
</body>
</html>
View Code

 

html-base标签

原文:https://www.cnblogs.com/orzjiangxiaoyu/p/13649061.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!