网页是拼串生成的
import java.io.*;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
@WebServlet("/")
public class index extends HttpServlet {
static final String T = "<li class='list-group-item'><span class='glyphicon glyphicon-folder-close'></span><a href='%'>%</a></li>";
static final String pre="<html> <head> <title>Tomcat</title> <meta charset='UTF-8'></meta> <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'> </head> <body> <div class='container-fluid'> <div class='row jumbotron'> <div class='col-md-2'> <img src='/icon.jpg' alt='icon.jpg' style='height:128;'> </div> <div class='col-md-10'> <h1 class='display-3'> Tomcat for 𝓛 𝓨 𝓕</h1> </div> </div> </div> <div class='container'> <div class='row'> <h2>War Packages Deployed on this Tomcat Server:</h2> </div> <div class='row' style='font-size: 22px;'> <ul class='list-group'>";
static final String stuff="</ul> </div> </div> </body> </html>";
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html;charset=UTF-8");
PrintWriter out = resp.getWriter();
StringBuilder sb = new StringBuilder();
sb.append(pre);
String path = "C:/Users/lyf/Desktop/apache-tomcat-10.0.4/webapps";
File[] files = new File(path).listFiles();
for (File f : files) {
if (f.isDirectory()) {
sb.append(T.replace("%", f.getName()));
}
}
sb.append(stuff);
out.print(sb.toString());
}
}