例如:http://www.java2000.net/f29
自动转发到
http://www.java2000.net/forumdisplay.jsp?fid=29
因为系统并不存在f29,所以使用了404的错误处理页面来实现这个功能
页面代码如下
1. <%@ page language="java" contentType="text/html; charset=GBK" isErrorPage="true" pageEncoding="GBK"%>
2. <%
3. response.setStatus(HttpServletResponse.SC_OK);
4. String key = (String) request.getAttribute("javax.servlet.forward.servlet_path");
5. if (key != null) {
6. int index = key.lastIndexOf("/");
7. if (index != -1) {
8. key = key.substring(index + 1);
9. if (key.startsWith("f") || key.startsWith("p")) {
10. try {
11. long id = Long.parseLong(key.substring(1));
12. String url = key.startsWith("f") ? "forumdisplay.jsp?fid=" : "viewthread.jsp?tid=";
13. %>
14. <jsp:forward page="<%=url+id%>"></jsp:forward>
15. <%
16. return;
17. } catch (Exception ex) {}
18. }
19. %>
20. <jsp:forward page="<%=response.encodeURL("search.jsp")%>"><jsp:param name="keyword" value="<%=key %>" /></jsp:forward>
21. <%
22. return;
23. }
24. }
25. %>
26. 对不起,您请求的页面没有找到!
自动转发到
http://www.java2000.net/forumdisplay.jsp?fid=29
因为系统并不存在f29,所以使用了404的错误处理页面来实现这个功能
页面代码如下
1. <%@ page language="java" contentType="text/html; charset=GBK" isErrorPage="true" pageEncoding="GBK"%>
2. <%
3. response.setStatus(HttpServletResponse.SC_OK);
4. String key = (String) request.getAttribute("javax.servlet.forward.servlet_path");
5. if (key != null) {
6. int index = key.lastIndexOf("/");
7. if (index != -1) {
8. key = key.substring(index + 1);
9. if (key.startsWith("f") || key.startsWith("p")) {
10. try {
11. long id = Long.parseLong(key.substring(1));
12. String url = key.startsWith("f") ? "forumdisplay.jsp?fid=" : "viewthread.jsp?tid=";
13. %>
14. <jsp:forward page="<%=url+id%>"></jsp:forward>
15. <%
16. return;
17. } catch (Exception ex) {}
18. }
19. %>
20. <jsp:forward page="<%=response.encodeURL("search.jsp")%>"><jsp:param name="keyword" value="<%=key %>" /></jsp:forward>
21. <%
22. return;
23. }
24. }
25. %>
26. 对不起,您请求的页面没有找到!