request.getContextPath();

来源:互联网 发布:海知智能 CTO 编辑:程序博客网 时间:2024/04/25 14:34

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


上面的语句是jsp中的代码:

那么他的含义就是为了得到一个路径,
做动态网站时,需要提交form表单
在表单的action里面就会这样来写
action="<%=path %>/add.do"
这样来提交到相应的servlet中去,这样可以避免路径的错误,而采用这样的相对路径会更好些

原创粉丝点击