系统配置常量,域名根目录方法

方法1:在servlet中通过代码获取,然后放置在session会话中.

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.getSession().setAttribute("basePath", basePath);

方法2:在系统常量类中定义 Constants.java

public static String ROOT = "http://localhost:8080/BNCAR2/";

在需要调用的地方直接用:Constants.ROOT,如:

<input type="hidden" name="basePath" id="basePath" value="<%=Constants.ROOT %>" />

推荐第二种方法更加方便~!



posted @ 2014-01-23 11:27  全新时代-小小程序员大梦想  阅读(313)  评论(0编辑  收藏  举报