我有一个关于文件写入权限被拒绝的问题。问题是,当我尝试在 webapps 文件夹下编写文件时,我提出了这个拒绝。但是,我在 /tmp 文件夹上写入相同的文件没有任何问题。我检查了这两者的差异,特别是在一个和每个文件夹的权限上。同 drwxr-xr-x root root /tmp drwxr-xr-x root root /usr drwxr-xr-x root root /usr/share drwxr-xr-x root root /usr/share/tomcat7-examples drwxr-xr -x root root /usr/share/tomcat7-examples/source drwxr-xr-x root root /usr/share/tomcat7-examples/source/webapps drwxr-xr-x root root /usr/share/tomcat7-examples/source /webapps/brain03 drwxr-xr-x root root /usr/share/tomcat7-examples/source/webapps/brain03/WEB-INF drwxr-xr-x root root /usr/share/tomcat7-examples/source/webapps/brain03 /WEB-INF/bbs
为什么我可以通过 /tmp 上的 jsp 页面保存文件而不是 /usr/share/tomcat7-examples/source/webapps/brain03/WEB-INF/bbs?
无论如何,我通过“chown -R tomcat7.tomcat7 /usr/share/tomcat7-examples/source”解决了这个问题。但是,谜底是存在的。每个目录是否有任何特殊的隐藏访问控制标签?
下面是相关的html和jsp源码。
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html;charset=euc-kr">
<TITLE>BBS Writing</TITLE>
</HEAD>
<BODY>
<H2>Write here</H2>
<FORM ACTION=BBSPost_new.jsp METHOD=POST>
Name: <INPUT TYPE=TEXT NAME=NAME><BR>
Title: <INPUT TYPE=TEXT NAME=TITLE><BR>
<TEXTAREA COLS=30 ROWS=5 NAME=CONTENT></TEXTAREA><BR>
<INPUT TYPE=SUBMIT VALUE='Save'>
</FORM>
</BODY>
</HTML>
<%@page contentType="text/html; charset=euc-kr"%>
<%@page import="java.io.*, java.util.Date"%>
<%
request.setCharacterEncoding("euc-kr");
String name = request.getParameter("NAME");
String title = request.getParameter("TITLE");
String content = request.getParameter("CONTENT");
Date date = new Date();
Long time = date.getTime();
String filename = time + ".txt";
String result;
PrintWriter writer = null;
try {
String filePath = application.getRealPath("/WEB-INF/bbs/" + filename);
writer = new PrintWriter(filePath);
writer.printf("Title: %s %n", title);
writer.printf("Writer: %s %n", name);
writer.println(content);
result = "SUCCESS";
}
catch (IOException ioe) {
out.println(ioe.getMessage());
result = "FAIL";
}
finally {
try {
writer.close();
}
catch (Exception e) {
}
}
response.sendRedirect("BBSPostResult.jsp?RESULT=" + result);
%>