gpt4 book ai didi

java - 为 JSP/Tomcat/Windows 设置目录权限

转载 作者:可可西里 更新时间:2023-11-01 12:09:06 25 4
gpt4 key购买 nike

<分区>

我有一个 Web 应用程序,其中包含一些以前在 Linux 机器上运行的 JSP。我需要让它在运行 Tomcat 5.5.29 的 Windows XP SP3 机器上运行。现在几乎一切正常,但只有一项:该应用程序能够将配置文件写入其 Windows 目录(即 C:\Program Files\Apache\Tomcat\webapps\myapp)。但是当它尝试这样做时,应用程序无法打开 FileOutputStream(返回 null)。如果我放下路径说明符,让它打开文件,它会在 Tomcat 目录中成功打开它。

第一行失败,第二行成功:

//  outputFile2 = new PrintWriter(new FileOutputStream(basePathName + "programAll.txt", false));
outputFile2 = new PrintWriter(new FileOutputStream("programAll.txt", false));

这是创建 basePathName 的代码:

    String basePathName = getBaseFilePath();  
...
public String getBaseFilePath()
{
String curDir = System.getProperty("catalina.home");
curDir = curDir + "/webapps/pubmed/";
curDir = "file:///" + formatPathNameForOS(curDir);
return curDir;
}

public String formatPathNameForOS(String pathName)
{
if (codeIsOnWindows())
{
pathName = pathName.replace('/','\\');
}
else
{
pathName = pathName.replace('\\','/');
}
return pathName;
}

这是异常消息:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:460)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
root cause

java.lang.NullPointerException
org.apache.jsp.updateMemberLists_jsp._jspService(updateMemberLists_jsp.java:1492)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

这是堆栈跟踪:

Aug 6, 2010 1:20:39 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at org.apache.jsp.updateMemberLists_jsp._jspService(updateMemberLists_jsp.java:1492)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:321)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:257)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.globus.tomcat.coyote.valves.HTTPSValve55.invoke(HTTPSValve55.java:45)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
at java.lang.Thread.run(Thread.java:595)

我查看了 updateMembersLists_jsp.java,这里是出现空指针的部分:

//create a file to write to the output
PrintWriter outputFile2 = null;
try
{
outputFile2 = new PrintWriter(new FileOutputStream(basePathName + "programAll.txt", false));
// outputFile2 = new PrintWriter(new FileOutputStream("programAll.txt", false));
}
catch (FileNotFoundException e)
{
out.write("<p><font color='red'>Error Saving</font></p>");
}
outputFile2.print(output); // THIS IS LINE 1492 -- NULL POINTER
outputFile2.close();

此外:我们现在从根目录而不是 Program Files 运行 Tomcat。我已经检查了 basePathName 并且计算正确。

现在我发现 Tomcat 的策略设置可能需要调整。我将以下几行添加到 catalina.policy 希望它能解决问题:

// The permissions granted to the pubmed webapp
grant codeBase "file:${catalina.home}/webapps/pubmed/-" {
permission java.io.FilePermission "${catalina.home}/webapps/pubmed/-", "read, write";
permission java.io.FilePermission "${catalina.home}/webapps/pubmed/*", "read, write";
};

这似乎没有任何效果。运行 tomcat 的 Windows 用户对 pubmed 目录具有读/写权限。除了这个 webapp 将文件写入它自己的目录似乎有问题之外,我还缺少什么?

肖恩

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com