0

我的服务器端是一个 JSP 应用程序,它托管在 Appache Tomcat 7(Eclipse 中的插件)上。我的客户端是:-

if(("GET").equalsIgnoreCase(request.getMethod())&&("Create Reimbursement").equalsIgnoreCase(request.getParameter("Create Reimbursement"))){ 
//crresult = lmktweb.createReimbursement(Integer.parseInt(request.getParameter("ID")), request.getParameter("EmpdID"), request.getParameter("DateCreated"), request.getParameter("Amount"),request.getParameter("Vendor"),request.getParameter("picpath"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.80.125:8080/UploadFileServerSide/UploadHandler.jsp");
MultipartEntity entity = new MultipartEntity();
System.out.println(request.getParameter("fname"));
if(request.getParameter("fname")!=""){
    File file = new File(request.getParameter("fname"));
    entity.addPart("data", new FileBody(file));
    httppost.setEntity(entity);    
    HttpResponse resp = httpclient.execute(httppost);
}

我的服务器端是: -

try {
                        String itemName = item.getName();
                        String fpath = "";
                        //item.
                        File root=File.listRoots()[0];
                        String extPath;
                        if(crdate!=""){
                            extPath = rei.HandlePathWithDate(crdate,getServletContext().getRealPath("images"));
                            fpath = extPath+"\\"+ppath;
                            fpath = extPath.replaceAll("/", "\\");
                        }   
                        else{

                            extPath= getServletContext().getRealPath("/");
                            fpath = extPath.concat("\\"+itemName);                              
                            fpath = extPath.replaceAll("/", "\\");                          

                        }
                        System.out.println("Saving as: " +fpath);
                        File f = new File(fpath);

                        f.setWritable(true);
                        f.setReadable(true);
                        item.write(f);

                    } catch (Exception e) {
                        e.printStackTrace();
                        response.setHeader("Error", e.getMessage());                            
                    }

但是在给定路径上写入文件时会产生以下错误:-

另存为:D:\Z-Main\Projects\Android Projects.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\UploadFileServerSide\ java.io.FileNotFoundException: D:\Z-Main\Projects\ Android Projects.metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\UploadFileServerSide(访问被拒绝)在 java.io.FileOutputStream.open(本机方法)在 java.io.FileOutputStream.(未知来源)在 java.io.FileOutputStream.(Unknown Source) 在 org.apache.commons.fileupload.disk.DiskFileItem.write(DiskFileItem.java:426) 在 org.apache.jsp.UploadHandler_jsp._jspService(UploadHandler_jsp.java:154) 在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:722) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.爪哇:第 432 章(HttpServlet.java:722) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 在 org.apache。 catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java: 472) 在 org.apache.catalina.valves.ErrorReportValve 的 org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)。在 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 的 org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 的调用(ErrorReportValve.java:98)。 .catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java :565) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1812) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor $Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org .apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) 在 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor .run(AprEndpoint.java:1812) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(来源不明)AccessLogValve.invoke(AccessLogValve.java:927) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) at org .apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565) 在 org.apache.tomcat.util.net.AprEndpoint$SocketProcessor .run(AprEndpoint.java:1812) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(来源不明)118) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler .process(AbstractProtocol.java:565) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1812) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java .util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)118) 在 org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) 在 org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler .process(AbstractProtocol.java:565) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1812) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java .util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)process(AbstractProtocol.java:565) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1812) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java。 util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)process(AbstractProtocol.java:565) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1812) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java。 util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

哪里有问题。我目前正在使用 Tomcat Eclipse 插件,控制台上出现此错误。我在 android 应用程序中调用相同的代码,它工作正常。请提供有用的详细信息。我试图编辑位于 eclipse 服务器插件文件夹中的 catalina.policy 文件并添加了以下行:-

grant codeBase " file:${catalina.base}/webapps/UploadFileServerSide/-" {
  ermission java.io.FilePermission "${tomcat.home}/-","read,write"; };

并从 Eclipse 重新启动服务器,期待不同的结果,但到目前为止还没有运气。我在哪里迷路了?

4

1 回答 1

0

当我使用 Servlet 而不是 JSP 并在提交页面时使用 POST 方法时,问题得到了解决。奇怪的!!!!因为其余的东西几乎是一样的。仍然困惑为什么会发生,因为我认为 Servlet 在服务器上具有与 JSP 相同级别的访问权限。可能是我的假设是错误的!

于 2012-10-02T13:04:37.553 回答