What does the path get from the server by getRealPath () in jsp

后端 未结 1 503
遇见更好的自我
遇见更好的自我 2021-01-29 11:30

I am using struts 1.3,jsp for developing application. I want to know what following code will return path from the server.

 path = getServlet().         


        
1条回答
  •  南方客
    南方客 (楼主)
    2021-01-29 11:39

    First of all: getRealPath is deprecated. (compare: Interface ServletRequest). You should try this instead (since spec 2.1):

    ServletContext context = session.getServletContext();
    String realContextPath = context.getRealPath(request.getContextPath());
    

    Earlier to this, it was highly depended on the server implementation. According to the spec it was allowed to return null if the application was deployed as a archived module (war, ear, etc.) I believe this never happened e.g. with WebLogic. It returned the path to the temp directory where the archives had been unpacked. So, to make a long answer short:

    Your code will end up with something like this:

    x:\your\path\on\drive\images\logos\somename.ext
    

    It's not possible to use this as an image URL.

    0 讨论(0)
提交回复
热议问题