zoukankan      html  css  js  c++  java
  • struts2获得需要的文件或者访问路径

    在struts2中,上传文件的时候遇到一个很好用但是失效的方法,找到如下替代。并且测试了一下request可以得到的相关路径。

    得到request对象:
    HttpServletRequest request = ServletActionContext.getRequest()
    得到当前项目在服务器的绝对路径(方法失效,但是可用): String path1
    = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/"; // D:javabaoapache-tomcat-7.0.34webappsillingsystemupload

    得到当前项目在服务器的绝对路径(推荐使用): String path2
    = request.getSession().getServletContext().getRealPath("/upload/"); // D:javabaoapache-tomcat-7.0.34webappsillingsystemupload

    得到根url:
    String path1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+"/";
    // http://127.0.0.1:8080/

    得到项目发布的名字: System.
    out.println(ServletActionContext.getRequest().getContextPath()); // /mly

    得到当前servlet路径; System.
    out.println(ServletActionContext.getRequest().getServletPath());
    // /hello_uploadTitle.action
  • 相关阅读:
    4.结构化机器学习项目
    九、LaTex中的浮动体
    第二章 决策树
    菜鸟教程C++(一)
    12月月计划与周计划
    目标检测常见错误
    Tensorflow object detection API(1)---环境搭建与测试
    爬取今日头条街拍美图
    BS4库详解
    requests库详解
  • 原文地址:https://www.cnblogs.com/moly/p/6831816.html
Copyright © 2011-2022 走看看