java - Websphere 中的 NullPointerException 异常?

标签 java servlets websphere

我使用PrintWriter对另一个servlet进行servlet调用。无法重定向特定目标URL。我的代码是

PrintWriter pw= null;
pw= response.getWriter();
pw.print("URL TO Redirect");
pw.close();

Websphere 系统错误日志:

java.lang.NullPointerException
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:485)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:301)
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:275)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
    at com.ibm.ws.tcp.channel.impl.WorkQueueManager.requestComplete(WorkQueueManager.java:557)
        at com.ibm.ws.tcp.channel.impl.WorkQueueManager.attemptIO(WorkQueueManager.java:607)
    at com.ibm.ws.tcp.channel.impl.WorkQueueManager.workerRun(WorkQueueManager.java:984)
    at com.ibm.ws.tcp.channel.impl.WorkQueueManager$Worker.run(WorkQueueManager.java:1069)
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1563)

最佳答案

pw.close; 应该是 pw.close();

否则您将尝试访问名为 close 的非私有(private)字段。如果存在的话,它可能是null

除此之外,您的代码看起来不错,NPE 原因在其他地方。

关于java - Websphere 中的 NullPointerException 异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20999027/

相关文章:

java - Servlet 2.3规范中关于Websphere session 管理策略和 session 相关内容的一些疑问

java - 更改来自 Websphere 的默认 axis2 Web 服务调用?

java - 无法导入已下载到 .m2 的依赖项

java - 按钮 ID 未解析

java - 拥有多页 GWT 应用程序的可行性

unit-testing - 在 JUnit 测试中运行 Jettys ServletTester

java - 如何缩短JSP中的数字?

java - 创建 QName 时本地部分不能是 "null"

java - 如何从控制台向 main 传递除 String args[] 之外的参数?

java - 提供 zip 服务的 JSP 损坏了文件