liagnzhian0620
2010-01-06 09:17 阅读 441

在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 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

    点赞 评论 复制链接分享
  • weixin_42519818 weixin_42519818 2010-01-06 09:23

    WEB-INF这个文件夹在服务器上是受保护的。也就是只有服务器有权利访问。打个比方,你在WEB-INF里存放一张图片,在页面上是引用不到的。

    点赞 评论 复制链接分享
  • xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx 2010-01-06 09:33

    info.txt ? info.properties

    点赞 评论 复制链接分享

相关推荐