下面例子中,first.jsp 帶參數(2)發ajax 請求invoke.jsp ,然後invoke.jsp 調用java 程式 Ev---getSuggestions()方法,給Ev執行個體化參數3,sugg = Ev(3), 調用程式參數用first.jsp給的2:sugg.getSuggestions(2), 結果最終返回給first.jsp 並顯示到 id 為lblOutput 的一個裡。
=========================================
first.jsp
-----------------------------------------------------------------------
ttp://www.w3.org/TR/html4/loose.dtd"">http://www.w3.org/TR/html4/loose.dtd">
=============================================================
invoke.jsp
------------------------------------------------------------------------------------
br /> "http://www.w3.org/TR/html4/loose.dtd">
==============================================================
app.Ev.java
------------------------------------------------
package app;
public class Ev {
private int lev;
public String getSuggestions (int reqInt){
int result = reqInt + lev;
return String.valueOf(result)lblOutput;
}
public Ev (int lev){
this.lev= lev;
}
}