操作系统是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();
}
}
}
请问这个问题怎么解决