2011-11-04 61 views
-2

我通常使用PHP,但需要使用我正在与之交互的服务器来设置此JSP。这里是我尝试代码:我可以使用JSP在我的服务器上移动文件吗?

<% 
String filename = request.getParameter("file"); 
filename = "C:\Tomcat 5.5\webapps\myapp\\" + filename; 
out.print(filename); 

ActiveXObject theObject = new ActiveXObject("Scripting.FileSystemObject"); 
File theFile = new theObject.GetFile(filename); 

theFile.Move("C:\Tomcat 5.5\webapps\myapp\processed\\"); 

%> 

的目标是在发送请求到http://www.thewebsite.com/myfile.jsp?file=x.txt和JSP文件中应采取x.txt,并将其移动到processed目录。

当我调用这个JSP文件时,我得到一个错误,说ActiveXObject cannot be resolved to a type ...所以,我想我不能这样做。

是否可以使用JSP来移动文件?

+0

JSP表示** Java **服务器页面。您应该阅读** Java ** api引用,而不是盲目地尝试使用显然只能在Windows上存在的对象。 Java是一种多平台语言。 http://download.oracle.com/javase/6/docs/api/。另外,阅读这篇文章:http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files –

回答

0

ActiveXObject cannot be resolved to a type 

通常意味着我们需要在那里的ActiveXObject驻留导入类。在JSP中使用import伪指令导入你需要的包。

<%@ page import="java.util.*" %> 

希望这有助于!

相关问题