goto.java
来自「java servlet编程源码」· Java 代码 · 共 28 行
JAVA
28 行
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class GoTo extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
// Determine the site where they want to go
String site = req.getPathInfo();
String query = req.getQueryString();
// Handle a bad request
if (site == null) {
res.sendError(res.SC_BAD_REQUEST, "Extra path info required");
}
// Cut off the leading "/" and append the query string
// We're assuming the path info URL is always absolute
String url = site.substring(1) + (query == null ? "" : "?" + query);
// Log the requested URL and redirect
log(url); // or write to a special file
res.sendRedirect(url);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?