WebLogic 12c中以编程方式包括JSP的RequestDispatcher的问题

WebLogic 12c中以编程方式包括JSP的RequestDispatcher的问题,第1张

WebLogic 12c中以编程方式包括JSP的RequestDispatcher的问题

我这样做:

@Overridepublic ServletOutputStream getOutputStream() throws IOException {    // this is called onLY in WebLogic    // created a custom outputstream that wraps your charArray    return new CustomOutputStream(this.charArray);}// custom outputstream to wrap charArray writerclass CustomOutputStream extends ServletOutputStream {    private WriterOutputStream out;    public CustomOutputStream(CharArrayWriter writer) {        // WriterOutputStream has a constructor without charset but it's deprecated, so change the UTF-8 charset to the one you use, if needed        this.out = new WriterOutputStream(writer, "UTF-8");    }    @Override    public boolean isReady() {        return true;    }    @Override    public void setWriteListener(WriteListener writeListener) {    }    @Override    public void write(int b) throws IOException {        this.out.write(b);        this.out.flush(); // it doesn't work without flushing    }}

我使用的

WriterOutputStream
是Apache Commons-io,因此必须在pom.xml中添加它:

<dependency>  <groupId>commons-io</groupId>  <artifactId>commons-io</artifactId>  <version>2.5</version></dependency>

我不知道您的jsp文件包含什么,但是我已经用一个简单的文件进行了测试,我相信它可以工作。我的jsp文件:

<b>Hello world</b><p>testing</p><ul>test<li>item</li><li>item2</li></ul>

输出(在浏览器中访问servlet时):

{"results":"<b>Hello world</b>nn<p>testing</p>nn<ul>testn<li>item</li>n<li>item2</li>n</ul>"}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5167104.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存