Spring Boot用浏览器关闭程序

来源:互联网 发布:js时间相减 编辑:程序博客网 时间:2024/05/22 04:48

application.properties

[html] view plain copy
  1. #启动url shutdown  
  2. endpoints.shutdown.enabled=true  


index.jsp

[html] view plain copy
  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%  
  3. String path = request.getContextPath();  
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  
  5. %>  
  6.   
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  8. <html>  
  9.   <head>  
  10.     <base href="<%=basePath%>">  
  11.       
  12.     <title>My JSP 'index.jsp' starting page</title>  
  13.       
  14.     <meta http-equiv="pragma" content="no-cache">  
  15.     <meta http-equiv="cache-control" content="no-cache">  
  16.     <meta http-equiv="expires" content="0">      
  17.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  18.     <meta http-equiv="description" content="This is my page">  
  19.     <!-- 
  20.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  21.     -->  
  22.   
  23.   </head>  
  24.     
  25.   <body>  
  26.      hello jsp  
  27.        
  28.      <form action="${pageContext.request.contextPath}/shutdown" method="post">  
  29.         <input type="submit" value="关闭"/>  
  30.      </form>  
  31.        
  32.   </body>  
  33. </html>  

在浏览器中访问jsp

http://localhost/sb/index.jsp


如果直接访问http://localhost/sb/shutdown会出现请求限定的错误,因为用浏览器直接跳转只能是GET

那这个Action只能用POST请求访问才会生效,所以利用form表单跳转来关闭程序

原创粉丝点击