栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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>"}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/447294.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号