我无法从jsp页面启动java方法

时间:2011-09-07 10:29:23

标签: jsp tomcat

我在服务器上传了jsp文件(index.jsp)和java文件(easyTesting.java),无法从easyTesting.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

我得到了下一个错误

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

你能帮我吗

1 个答案:

答案 0 :(得分: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翻译成本地文件路径吗?实际上,这些斜杠很可能被解释为目录名,因此您至少需要确保存在任何父目录。