Web逻辑服务器的根目录(或文件夹)的位置在哪里

时间:2018-12-19 19:46:10

标签: jsp weblogic12c

我想将文件上传到我的Web逻辑域(或服务器,我不知道):

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItemIterator;
import org.apache.commons.fileupload.FileItemStream;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

import com.crimsonlogic.utls.Uploader;

/**
 * Servlet implementation class DummyServlet
 */
@WebServlet("/DummyServlet")
public class DummyServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public DummyServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath()+"...\n\n");
        boolean isMultiPart = ServletFileUpload.isMultipartContent(request);
        if(isMultiPart){
            ServletFileUpload upload = new ServletFileUpload();
            try{
                FileItemIterator itr = upload.getItemIterator(request);
                while(itr.hasNext()){
                    FileItemStream item = itr.next();
                    if(!item.isFormField()){
                        String path = "../serverFiles/";
                        if(Uploader.subirImagen(path, item,"test"))
                            response.getWriter().println("success");
                        else response.getWriter().println("Failure);
                    }
                }
            }catch(FileUploadException ex){
                ex.printStackTrace();
            }
    }}

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

在glassfish服务器中,我们曾经将文件存储在 docroot 内部的文件夹中。我们还必须在sun-web.xml中添加一个属性来实现此目的:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app error-url="">
  <context-root>/vuda</context-root>
  <property description="Uploaded Images" name="images" value="from=/images/* dir=./docroot/"/>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</sun-web-app>

我现在的问题是:如何将文件上传到weblogic域? Weblogic服务器中的“ docroot”文件夹相当于什么?。

PD:另外,我不想放置绝对路径,我不想使用相对路径来获得更好的OS支持。

0 个答案:

没有答案