Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Database/JDBC/SQL/JDO/Hibernate  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 Re:ResultSet返回为null? [Re:neil99]
neil99





发贴: 19
积分: 0
于 2006-04-15 10:48 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
在jsp里
好象这里写相对路径是错的
得是绝对路径才行
要重起服务器, 错误已经解决了

但为什么java应用程序里就行呢

找到一个专门来获取绝对路径的javaBean(path_test.java)
来解决问题
//#############################

package pathtest;
import java.io.*;
import javax.servlet.*;
import javax.servlet.jsp.PageContext;//导入PageContext类,不要忘了
public class path_test
{

protected ServletContext m_application;
private boolean m_denyPhysicalPath;
public path_test()
{

}
public final void initialize(PageContext pageContext)
throws ServletException
{
m_application = pageContext.getServletContext();

}

public String getPhysicalPath(String filePathName, int option)
throws IOException
{
String path = new String();
String fileName = new String();
String fileSeparator = new String();
boolean isPhysical = false;
fileSeparator=System.getProperty("file.separator");
if(filePathName == null)
throw new IllegalArgumentException("There is no specified destination file (1140).");
if(filePathName.equals(""))
throw new IllegalArgumentException("There is no specified destination file (1140).");
if(filePathName.lastIndexOf("\\") >= 0)
{
path = filePathName.substring(0, filePathName.lastIndexOf("\\"));
fileName = filePathName.substring(filePathName.lastIndexOf("\\") + 1);
}
if(filePathName.lastIndexOf("/") >= 0)
{
path = filePathName.substring(0, filePathName.lastIndexOf("/"));
fileName = filePathName.substring(filePathName.lastIndexOf("/") + 1);
}
path = path.length() != 0 ? path : "/";
java.io.File physicalPath = new java.io.File(path);
if(physicalPath.exists())
isPhysical = true;
if(option == 0)
{
if(isVirtual(path))
{
path = m_application.getRealPath(path);
if(path.endsWith(fileSeparator))
path = path + fileName;
else
path = String.valueOf((new StringBuffer(String.valueOf(path))).append(fileSeparator).append(fileName));
return path;
}
if(isPhysical)
{
if(m_denyPhysicalPath)
throw new IllegalArgumentException("Physical path is denied (1125).");
else
return filePathName;
} else
{
throw new IllegalArgumentException("This path does not exist (1135).");
}
}
if(option == 1)
{
if(isVirtual(path))
{
path = m_application.getRealPath(path);
if(path.endsWith(fileSeparator))
path = path + fileName;
else
path = String.valueOf((new StringBuffer(String.valueOf(path))).append(fileSeparator).append(fileName));
return path;
}
if(isPhysical)
throw new IllegalArgumentException("The path is not a virtual path.");
else
throw new IllegalArgumentException("This path does not exist (1135).");
}
if(option == 2)
{
if(isPhysical)
if(m_denyPhysicalPath)
throw new IllegalArgumentException("Physical path is denied (1125).");
else
return filePathName;
if(isVirtual(path))
throw new IllegalArgumentException("The path is not a physical path.");
else
throw new IllegalArgumentException("This path does not exist (1135).");
}

else
{
return null;
}

}
private boolean isVirtual(String pathName) //判断是否是虚拟路径
{
if(m_application.getRealPath(pathName) != null)
{
java.io.File virtualFile = new java.io.File(m_application.getRealPath(pathName));
return virtualFile.exists();
}

else
{
return false;
}
}

}




学习java的工具(IDE)有什么?

话题树型展开
人气 标题 作者 字数 发贴时间
22004 ResultSet返回为null? neil99 2464 2006-04-04 14:21
19820 Re:ResultSet返回为null? Jcat 132 2006-04-04 15:01
19521 Re:ResultSet返回为null? neil99 7 2006-04-15 10:28
20749 Re:ResultSet返回为null? neil99 3145 2006-04-15 10:48
19566 Re:ResultSet返回为null? neil99 26 2006-04-04 15:15
19585 Re:ResultSet返回为null? Jcat 17 2006-04-04 17:13
19560 Re:ResultSet返回为null? neil99 65 2006-04-04 17:49
19603 Re:ResultSet返回为null? chy305 14 2006-04-04 22:10
19921 Re:ResultSet返回为null? Jcat 16 2006-04-05 08:19
19443 Re:ResultSet返回为null? neil99 20 2006-04-05 08:51
19850 Re:ResultSet返回为null? tomcatexpert 166 2006-04-11 18:16
19550 Re:ResultSet返回为null? neil99 18 2006-04-05 08:53
19472 Re:ResultSet返回为null? neil99 29 2006-04-15 10:14

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923