外部在 Response 对象中添加内容
我有一个简单的应用程序,它在从 servlet 获取一些数据后将 jsp 文件呈现到浏览器中。现在我想以某些 HTML 标记的形式将一些数据添加到来自 jsp 的响应对象中。
我制作了一个过滤器和响应包装器,它通过返回自定义 PrintWriter 来覆盖 getWriter 方法:
StringWriter sw = new StringWriter();
public PrintWriter getWriter() {
return new PrintWriter(sw);
}
现在我可以使用 getString 函数从该响应对象中检索字符串
public getString(){
return sw.toString();
}
我可以使用 添加字符串中的内容
str.split("<tag where I have to add>");
但现在我想要将此字符串呈现到我的浏览器中。
我是否需要创建其他一些包装对象?或者请建议任何其他方法来实现这一目标。任何帮助将不胜感激。
谢谢。
I have a simple application which renders a jsp file into the browser after getting some data from a servlet.Now I want to add some data in the form of some HTML Tag into the response object coming out of the jsp.
I have made a filter and response wrapper which overrides the getWriter method by returning a custom PrintWriter as:
StringWriter sw = new StringWriter();
public PrintWriter getWriter() {
return new PrintWriter(sw);
}
Now I am able to retrieve the string from this response object using getString function
public getString(){
return sw.toString();
}
And I am able to add the content in the string using
str.split("<tag where I have to add>");
But now I want to render this string into my Browser.
Will I have to create some other Wrapper object? Or please suggest any other way to achieve this.Any help will be appreciated.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在否决响应对象的现有编写者。您应该保留对该作者的引用,并最终将最终/修改后的内容写给该作者。
You are overruling the existing writer of the response object. You should keep a reference to that one and in the end write the final/modified content to that writer.