liagnzhian0620 2010-01-06 09:17
浏览 490
已采纳

在weblogic中怎么访问web-inf下的info.txt

操作系统是liunx,应用服务器是weblogic10.2.3.1
我在web-inf目录下有一个info.txt配置文件,把web程序打成war包放在weblogic服务器中,在访问中却不能找到这个目录?
info.txt如下:/login.do=com.ouruan.mvctemplate.service.LoginService

public class ServletAction extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doPost(request, response);
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    //设置字符编码
    response.setContentType("text/html charset=utf-8");
    //获取请求路径
    String path = request.getServletPath();
    System.out.println(path);
    //获取配置文件info.txt的全路径
    String filePath = this.getServletContext().getRealPath("WEB-INF"+File.separator+"info.properties");
    System.out.println(filePath);

// String webName = request.getContextPath();
//// 协议名称+服务器地址+端口号+web应用的名称
// String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+webName+
// File.separator+"WEB-INF"+File.separator+"info.properties";
// System.out.println(basePath);
ServicesFactory factory = new ServicesFactory(filePath);
如果 这里用filePath会抛出异常:
emplate.war path:/mvctemplate spec-version:2.5]] Servlet failed with Exception
java.lang.NullPointerException
at java.io.FileInputStream.(FileInputStream.java:103)
at java.io.FileInputStream.(FileInputStream.java:66)
at com.ouruan.mvctemplate.util.ServicesFactory.(ServicesFactory.java:25)
at com.ouruan.mvctemplate.control.ServletAction.doPost(ServletAction.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Truncated. see log file for complete stacktrace

如果用basePath会抛出异常:
<[ServletContext@10055979[app:_appsdir_mvctemplate_war module:mvctemplate.war path:/mvctemplate spec-version:2.5]] Servlet failed with Exception
java.lang.NullPointerException
at java.io.FileInputStream.(FileInputStream.java:103)
at java.io.FileInputStream.(FileInputStream.java:66)
at com.ouruan.mvctemplate.util.ServicesFactory.(ServicesFactory.java:25)
at com.ouruan.mvctemplate.control.ServletAction.doPost(ServletAction.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Truncated. see log file for complete stacktrace

/login.do
http://localhost:7001/mvctemplate/info.properties
java.io.FileNotFoundException: http:/localhost:7001/mvctemplate/info.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.(FileInputStream.java:106)
at java.io.FileInputStream.(FileInputStream.java:66)
at com.ouruan.mvctemplate.util.ServicesFactory.(ServicesFactory.java:25)
at com.ouruan.mvctemplate.control.ServletAction.doPost(ServletAction.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3594)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
key--/login.do
className--null
java.lang.NullPointerException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.ouruan.mvctemplate.util.ServicesFactory.getInfo(ServicesFactory.java:47)
at com.ouruan.mvctemplate.control.ServletAction.doPost(ServletAction.java:38)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:175)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3594)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

    try {
        InterService service = factory.getInfo(path);
        String forwardpath = service.getService(request, response);
        request.getRequestDispatcher(forwardpath).forward(request, response);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

}
请问这个问题怎么解决

  • 写回答

3条回答 默认 最新

  • wanghaolovezlq 2010-01-13 17:12
    关注

    你这样取路径就不对了
    String filePath = this.getServletContext().getRealPath("WEB-INF"+File.separator+"info.properties");

    参考下文章
    http://blog.csdn.net/shendl/archive/2006/12/03/1427475.aspx

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Xsheii7我安装这个文件的时候跳出来另一个文件已锁定文件的无一部分进程无法访问。这个该怎么解决
  • ¥15 unity terrain打包后地形错位,跟建筑不在同一个位置,怎么办
  • ¥15 FileNotFoundError 解决方案
  • ¥15 uniapp实现如下图的图表功能
  • ¥15 u-subsection如何修改相邻两个节点样式
  • ¥30 vs2010开发 WFP(windows filtering platform)
  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求