java如何获取jsp页面上传的文件路径 20 前台jsp: <form action="AA.do?method=yktAdd" method="post" > <input type='text'
来源:互联网 发布:淘宝超级店长使用方法 编辑:程序博客网 时间:2024/05/18 07:47
20
前台jsp: <form action="AA.do?method=yktAdd" method="post" > <input type='text' name='textfield' id='textfield' class='txt' /> <input type='button' class='btn' value='浏览...' /> <input type="file" name="excel"...展开
松籽黄 | 浏览 20656 次 问题未开放回答 举报
推荐于2016-08-04 02:01:51最佳答案
java文件中获得路径
Thread.currentThread().getContextClassLoader().getResource("") //获得资源文件(.class文件)所在路径
ClassLoader.getSystemResource("")
Class_Name.class.getClassLoader().getResource("")
Class_Name.class .getResource("/")
Class_Name.class .getResource("") // 获得当前类所在路径
System.getProperty("user.dir") // 获得项目根目录的绝对路径
System.getProperty("java.class.path") //得到类路径和包路径
打印输出依次如下:
file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/
file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/
file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/
file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/
file:/F:/work_litao/uri_test/WebContent/WEB-INF/classes/com/xml/imp/
F:\work_litao\uri_test
F:\work_litao\uri_test\WebContent\WEB-INF\classes;F:\work_litao\uri_test\WebContent\WEB-INF\lib\dom4j.jar
2、 JSP中获得当前应用的相对路径和绝对路径
根目录所对应的绝对路径:request.getRequestURI()
文件的绝对路径 :application.getRealPath(request.getRequestURI());
当前web应用的绝对路径 :application.getRealPath("/");
取得请求文件的上层目录:new File(application.getRealPath(request.getRequestURI())).getParent()
3.1 JSP中获得当前应用的相对路径和绝对路径
根目录所对应的绝对路径:request.getRequestURI()
文件的绝对路径 :application.getRealPath(request.getRequestURI());
当前web应用的绝对路径 :application.getRealPath("/");
取得请求文件的上层目录:new File(application.getRealPath(request.getRequestURI())).getParent()
3、Servlet中获得当前应用的相对路径和绝对路径
根目录所对应的绝对路径:request.getServletPath();
文件的绝对路径 :request.getSession().getServletContext().getRealPath(request.getRequestURI())
webapp路径:request.getSession().getServletContext().getRealPath("/")
当前web应用的绝对路径 :servletConfig.getServletContext().getRealPath("/");
(ServletContext对象获得几种方式:
javax.servlet.http.HttpSession.getServletContext()
javax.servlet.jsp.PageContext.getServletContext()
javax.servlet.ServletConfig.getServletContext()
)
阅读全文
0 0
- java如何获取jsp页面上传的文件路径 20 前台jsp: <form action="AA.do?method=yktAdd" method="post" > <input type='text'
- <form method=post action="addNew_hxxm.jsp" name="form1"enctype="multipart/form-data">
- <form action="get.php" method="post" id="tform"> <input type="text" name="one"> <a href="jav
- <FORM action=reg.asp?action=apply method=post> <INPUT type=submit value="请认真查看<服务条款和声明>(10
- <s:form action="user!regist" method="post">
- 关于jsp中<input type="file">获取路径问文件名,获取完全路径问题
- 关于jsp中<input type="file">获取路径问文件名,获取完全路径问题
- Form表单中method="post/get'的区别
- Form表单中method="post/get"的区别
- Form表单中method="post/get'的区别
- Form表单中method="post/get'的区别
- Form表单中method="post/get'的区别
- Form表单中method="post/get'的区别
- Form表单中method="post/get'的区别
- Form表单中method="post/get'的区别
- 解决JSP的Form表单提交method=get时乱码
- 如何获取input type=file的路径
- 关于input type=file 获取文件的路径问题
- Android UI界面中短暂消息提示实现
- 单选框为什么用radio表示?
- 【java多线程】多线程的创建三种方式--笔记
- [备忘录]-Eclipse4.7优化配置
- 近期deep learning做图像质量评价(image quality assessment)的论文4
- java如何获取jsp页面上传的文件路径 20 前台jsp: <form action="AA.do?method=yktAdd" method="post" > <input type='text'
- 通达OA设计报表的自动合计公式
- 祝贺中兴虚拟化团队成员获Google开源贡献奖
- 如何读懂火焰图?
- material admin 下载_material admin template_material admin 模板_一个很牛逼的angular ui
- Logback 日志异步输出数据库(Oracle)
- 面向对象--内部类
- 干货|一文带你了解 Apache Hive2.x 的四大特性
- C语言 参数概念