2011-09-07 26 views
0

我上传服务器上的jsp文件(index.jsp)和java文件(easyTesting.java),无法从easyTesting.java启动该方法。我无法从jsp页面启动java方法

用途:在UNIX

Tomcat的6,服务器版本5.1.41-3ubuntu12.10

这是我的index.jsp

`<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
    pageEncoding="ISO-8859-1"%> 

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 

"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<title>Layer Easy testing</title> 
</head> 

<body> 
<form action="poi.jsp" method="post"> 
<INPUT type="button" value="Create script file" onClick = <% link.startCode(); %> 

"window.location.reload()"><br> 
<br> 
Select POIs type 
<div align="left"><br> 
<input type="radio" name="poi" value="1" checked > dynamic<br> 
<input type="radio" name="poi" value="2">static<br> 
<input type="radio" name="poi" value="3"> both<br> 

<INPUT type="submit" value="save" ><br> 

</div> 
</form> 
</body> 
</html> 

`

和java文件 包装;

import java.io.*; 

public class easyTesting 
{ 
    public void startCode() 
{ 
    File f = new File("http:79.125.23.143/~lezv/layertestnew.php"); 
    if(!f.exists()) 
    { 
    f.createNewFile(); 
    } 
    else 
    { 
    f.delete(); 
    } 
    }enter code here 

    } 

当我打开http://79.125.23.143:8080/lezv/index.jsp

我得到下一个errror

description The server encountered an internal error() that prevented it from 

fulfilling this request. 

exception 

org.apache.jasper.JasperException: An exception occurred processing JSP page 

/index.jsp at line 12 

9: <jsp:useBean id="link" class = "layar.easyTesting" /> 
10: <body> 
11: <form action="poi.jsp" method="post"> 
12: <INPUT type="button" value="Create script file" onClick = <% link.startCode(); %> 

"window.location.reload()"><br> 
13: <br> 
14: Select POIs type 
15: <div align="left"><br> 


Stacktrace: 
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.ja 
va:510) 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:407) 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
    root cause 

    java.io.IOException: Permission denied 
java.io.UnixFileSystem.createFileExclusively(Native Method) 
java.io.File.createNewFile(File.java:900) 
layar.easyTesting.startCode(easyTesting.java:12) 
org.apache.jsp.index_jsp._jspService(index_jsp.java:73) 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:717) 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:2 

能否请你帮我

回答

0

的方法被调用,但遇到异常:

java.io.IOException: Permission denied 
java.io.UnixFileSystem.createFileExclusively(Native Method) 
java.io.File.createNewFile(File.java:900) 
layar.easyTesting.startCode(easyTesting.java:12) 

该例外说明您无权创建该文件。

File f = new File("http:79.125.23.143/~lezv/layertestnew.php"); 

这是一个奇怪的文件名。难道你需要将你想要的PHP的URL翻译成本地文件路径吗?实际上,这些斜线很可能会被解释为目录名称,因此您至少需要确保存在任何父目录。

+0

Tomcat位于unix系统,这就是为什么我使用/而不是\\。那么我应该如何为php文件编写filepath,该文件应该在服务器上的目录http://79.125.23.143/~lezv/ – Alex

+0

上创建。取决于...可能是“/home/lezv/htdocs/layertestnew.php”例。 – Thilo

+0

我在filepath中编写layertestnew.php,现在我有另一个错误org.apache.jasper.JasperException:/index.jsp(9,0)useBean类属性的值layar.Testing无效。 \t org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40) \t org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) \t org.apache.jasper.compiler。 ErrorDispatcher.jspError(ErrorDispatcher.java:148) \t org.apache.jasper.compiler.Generator $ GenerateVisitor.visit(Generator.java:1220) – Alex