从jsp调用bean方法 [英] Invoke bean method from jsp
本文介绍了从jsp调用bean方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何从jsp调用bean方法. 就像是.在按钮[Hey]上单击,我要打印"Hello world". 谢谢.
I would like to know how to Invoke bean method from jsp. something like. On click of button [Hey] i would like to print "Hello world". Thank you.
推荐答案
Go ahead with JSF. Here's how your requirement would look like:
查看(test.xhtml
)
<!DOCTYPE html>
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
>
<h:head>
<title>JSF Hello World</title>
</h:head>
<h:body>
<h:form>
<h:commandButton value="Hey" action="#{bean.hey}">
<f:ajax render=":result" />
</h:commandButton>
</h:form>
<h:outputText id="result" value="#{bean.result}" />
</h:body>
</html>
型号(Bean.java
)
@ManagedBean
@RequestScoped
public class Bean {
private String result;
public void hey() {
result = "Hello World!";
}
public String getResult() {
return result;
}
}
就是这样.
这篇关于从jsp调用bean方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文