% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/" ; %base href="%=basePath%" 例如: %-- Created by IntelliJ IDEA. User: Administrator Date:
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <base href="<%=basePath%>">
例如: <%-- Created by IntelliJ IDEA. User: Administrator Date: 2019/6/5 Time: 15:02 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <html> <link rel="stylesheet" href="css/style.css"> <head> <base href="<%=basePath%>"> <title>Title</title> </head> <script src="script/jquery-1.8.3.js"></script> <script> $(function(){ //为所有的删除的超链接增加单击事件 $(".delete").click(function(){ //获取到超链接的请求的href的路径 var href=$(this).attr("href"); //把form的action属性设置成href $("form").attr("action",href); //提交表单 $("form").submit(); //阻止原来的单机事件 return false; }); }); </script> <body> <form action="" method="post"> <input type="hidden" name="_method" value="DELETE"/> </form> <table border="1"> <tr> <td colspan="5"> 查看所有部门 </td> </tr> <tr> <th>部门编号</th> <th>部门名称</th> <th>部门位置</th> <th>表操作</th> </tr> <c:forEach items="${depts}" var="dept"> <tr> <td>${dept.deptno}</td> <td>${dept.dname}</td> <td>${dept.loc}</td> <td> <a href="delete/${dept.deptno}" class="delete">删除</a> <a href="toUpdate/${dept.deptno}">修改</a> </td> </tr> </c:forEach> <tr> <td colspan="5"> <a href="toSave">添加部门</a> </td> </tr> </table> </body> </html>