jfinal获取当前访问路径,端口号,相对路径等
如果是在java后端想获取路径:
public void getRootParam() throws Exception {
System.out.println(getRequest().getRequestURL());
System.out.println(getRequest().getServerPort());
System.out.println(getRequest().getContextPath());
}
输出结果:
http://192.168.58.40:8081/eova/
8080
/eova
如果想在前端获取路径可以这样做:
//动态资源配置
public void configHandler(Handlers me) {
me.add(new ContextPathHandler("contex_path"));
}
把上面配置在配置类里面,然后前端页面用${contex_path}就可以替代<%=request.getContextPath()%>了
转载请注明原文地址: https://www.6miu.com/read-34064.html