我有一个 servlet 方法,我需要在其中传递一个 json 对象。此 json 对象将在托管 bean (JSF) 之一中创建。我只是尝试将 bean 注入 servlet 以获取 json 对象,但我得到运行时异常,可能是不可能的。所以我想从 JSF bean 调用 servlet。任何想法如何从bean调用?
小服务程序
private static final long serialVersionUID = 1L;
TopicController topicController;
TopicBean topicBean;
List<JsonTopicObj> jsonTopicList;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException {
// here code for subscription
Meteor mateor = Meteor.build(req).addListener(
new MyAtmosphereResourceEventListener());
boolean isLongPolling = true;
if (mateor.transport() == LONG_POLLING) {
isLongPolling = true;
} else {
isLongPolling = false;
}
System.out.println(" Now in the Get method of Atmosphere");
// create the broadcaster for the particular topic
String topicId = "default"; // for all users right now
Broadcaster broadcaster = BroadcasterFactory.getDefault().lookup(
topicId, true);
//set that broeadcaster
mateor.setBroadcaster(broadcaster);
mateor = mateor.resumeOnBroadcast(isLongPolling);
mateor.suspend(-1);
}
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {}
JSF 豆
@ManagedBean(name = "testController")
@RequestScoped
public void listAllTopics() {
JsonTopicObj jsonTopicObj;
StringWriter out = new StringWriter();
JsonFactory jfactory = new JsonFactory();
ObjectMapper mapper = new ObjectMapper();
jsonTopicList = new ArrayList<JsonTopicObj>();
for (int i = 0; i < topicBean.getTopicVOArray().length; i++) {
jsonTopicObj = new JsonTopicObj();
......................
}
mapper.writeValue(out, jsonTopicList);
现在我需要调用 servlet dopost 方法并发送“out.toString()”