可能是String myUrl=request.getRequestURI();有问题,你把myUrl输出,看看是否跟你想象的值一样
解决方案 »
- java写的网页游戏如何做外挂?谁知道哦?
- 菜鸟问题--为什么无法关闭对话框
- 我要学习用Java的Swing进行比较大项目的UI设计,请问什么工具好些?
- 有关XMLGUI的教程或者API文章,急求,谢谢
- 关于CallableStatement执行效率问题
- <script defer>之中的“defer”是名字吗,<script> 的定义方法谁有明细啊,强以贴出来吗?
- 请jFresH_MaN(TM)进来领分。。。
- 1000分!!!!redhat 7.2下tomcat4.1.12设置为80端口启动
- 用JNDI查找home接口时,该如何写
- 请问如何将写好的JDK程序做成可被直接解释运行的JRE文件?
- about java&&Tdg.net
- 基本问题
try{
String myUrl=request.getRequestURI();
URL url=new URL(myUrl);
String myPath=url.getPath();
}
catch(MalformedURLException e){}
如果用url调硬盘上的一个文件也需要用file://...
public static final URL createURL(String fileName) throws Exception
{
URL url = null;
try
{
url = new URL(fileName);
}
catch (MalformedURLException ex)
{
File f = new File(fileName);
try
{
String path = f.getAbsolutePath();
String fs = System.getProperty("file.separator");
if (fs.length() == 1)
{
char sep = fs.charAt(0);
if (sep != '/')
path = path.replace(sep, '/');
if (path.charAt(0) != '/')
path = '/' + path;
}
path = "file://" + path;
url = new URL(path);
}
catch (MalformedURLException e)
{
System.out.println("Cannot create url for: " + fileName);
throw new Exception(e.getMessage());
}
}
return url;
}