jsp傳遞引數到Bean, 得到的總是 null
我要從JSP的 form 輸入一個字元值,傳遞到 JavaBean 中,如下:
(1) index.jsp
---------------------------------
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>eCoin Client</title>
</head>
<body>
<h3>eCoin Client - Obtain Balance according to the PIN</h3>
<form method="POST" action="getpinbal.jsp">
PIN: <input type="text" name="xpin"><br>
<input type="submit" name="action" value="submit">
<input type="reset" name="reset" value="reset">
</form>
</body>
</html>
(2) getpinbal.jsp
-----------------------------------
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="gpin" class="eCoinClient.getpinbal" scope="session" />
<jsp:setProperty name="gpin" property="xpin" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Obtain result from Beans - JSP Page</title>
</head>
<body>
<h3>JSP Page</h3>
<%--
The pin is: <%= eCoinClient.getXpin() %> <br/>
The balance is: <%= eCoinClient.getXbal() %> <br/>
--%>
The pin is: <jsp:getProperty name="gpin" property="xpin"/> <br/>
The balance is: <jsp:getProperty name="gpin" property="xbal"/> <br/>
</body>
</html>
(3) getpinbal.java
------------------------
/* getpinbal.java Created on 2007年10月25日, 下午11:03 @author admin */
package eCoinClient;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import eCoinJsp.ECoinWs;
public class getpinbal {
String xpin;
float xbal;
public void setXpin(String xpin){
this.xpin = xpin;
}
public String getXpin() {
return xpin;
}
public void setXbal(float xbal) {
this.xbal = xbal;
}
public float getXbal() {
return xbal;
}
/** Creates a new instance of getpinbal */
public getpinbal() throws FileNotFoundException {
FileOutputStream fout; // declare a file output object
PrintStream fp; // declare a print stream object
fout = new FileOutputStream("C:\\getpin.txt");
fp = new PrintStream(fout);
fp.println ("1from value " + this.getXpin());
try { // Call Web Service Operation
eCoinJsp.ECoinWsService service = new eCoinJsp.ECoinWsService();
eCoinJsp.ECoinWs port = service.getECoinWsPort();
// TODO initialize WS operation arguments here
java.lang.String paraePin = this.getXpin();
// TODO process result here
fp.println ("2from form2: " + paraePin);
// fp.close();
eCoinJsp.ECoin result = port.getBalance(paraePin);
// System.out.println("Result = "+result);
fp.println ("3from ws-epin: " + result.getEpin());
fp.println ("4from ws-ebal: " + result.getEbal());
fp.close();
this.setXbal(result.getEbal());
} catch (Exception ex) {
// TODO handle custom exceptions here
ex.printStackTrace();
}
}
}
我在 getpinbal.java 輸出接受到的值,this.getXpin() 總是 null.
老大請看看是什麼問題?謝謝。
(1) index.jsp
---------------------------------
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>eCoin Client</title>
</head>
<body>
<h3>eCoin Client - Obtain Balance according to the PIN</h3>
<form method="POST" action="getpinbal.jsp">
PIN: <input type="text" name="xpin"><br>
<input type="submit" name="action" value="submit">
<input type="reset" name="reset" value="reset">
</form>
</body>
</html>
(2) getpinbal.jsp
-----------------------------------
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="gpin" class="eCoinClient.getpinbal" scope="session" />
<jsp:setProperty name="gpin" property="xpin" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Obtain result from Beans - JSP Page</title>
</head>
<body>
<h3>JSP Page</h3>
<%--
The pin is: <%= eCoinClient.getXpin() %> <br/>
The balance is: <%= eCoinClient.getXbal() %> <br/>
--%>
The pin is: <jsp:getProperty name="gpin" property="xpin"/> <br/>
The balance is: <jsp:getProperty name="gpin" property="xbal"/> <br/>
</body>
</html>
(3) getpinbal.java
------------------------
/* getpinbal.java Created on 2007年10月25日, 下午11:03 @author admin */
package eCoinClient;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import eCoinJsp.ECoinWs;
public class getpinbal {
String xpin;
float xbal;
public void setXpin(String xpin){
this.xpin = xpin;
}
public String getXpin() {
return xpin;
}
public void setXbal(float xbal) {
this.xbal = xbal;
}
public float getXbal() {
return xbal;
}
/** Creates a new instance of getpinbal */
public getpinbal() throws FileNotFoundException {
FileOutputStream fout; // declare a file output object
PrintStream fp; // declare a print stream object
fout = new FileOutputStream("C:\\getpin.txt");
fp = new PrintStream(fout);
fp.println ("1from value " + this.getXpin());
try { // Call Web Service Operation
eCoinJsp.ECoinWsService service = new eCoinJsp.ECoinWsService();
eCoinJsp.ECoinWs port = service.getECoinWsPort();
// TODO initialize WS operation arguments here
java.lang.String paraePin = this.getXpin();
// TODO process result here
fp.println ("2from form2: " + paraePin);
// fp.close();
eCoinJsp.ECoin result = port.getBalance(paraePin);
// System.out.println("Result = "+result);
fp.println ("3from ws-epin: " + result.getEpin());
fp.println ("4from ws-ebal: " + result.getEbal());
fp.close();
this.setXbal(result.getEbal());
} catch (Exception ex) {
// TODO handle custom exceptions here
ex.printStackTrace();
}
}
}
我在 getpinbal.java 輸出接受到的值,this.getXpin() 總是 null.
老大請看看是什麼問題?謝謝。
相關文章
- JSP中怎樣傳遞引數到彈出視窗?JS
- 面試官問:Go 中的引數傳遞是值傳遞還是引用傳遞?面試Go
- Java引數傳遞是傳值還是傳引用?Java
- JSP向後臺傳遞引數的四種方式JS
- 引數傳遞方式必須是const引用傳遞
- 引數傳遞
- struts2的action與jsp之間傳遞引數JS
- Go語言引數傳遞是傳值?還是傳引用 ?Go
- Go語言引數傳遞是傳值還是傳引用Go
- 在多個JSP頁面之間傳遞引數JS
- JS的方法引數傳遞(按值傳遞)JS
- JNI傳遞引數
- Mybatis引數傳遞MyBatis
- JSP中四種傳遞引數中文亂碼問題JS
- 在得到ejb遠端物件時,能否傳引數給無狀態session bean?物件SessionBean
- go語言引數傳遞到底是傳值還是傳引用Go
- 請求引數的傳遞
- 函式的引數傳遞函式
- java 中引數的傳遞Java
- mybatis傳遞引數到mapping.xmlMyBatisAPPXML
- ajax傳遞引數給springmvc總結[轉]SpringMVC
- 可否在JSP中向applet傳遞多個引數?JSAPP
- React事件傳遞引數React事件
- 路由元件傳遞引數路由元件
- GO中的函式設計時候,引數傳遞選擇傳遞值還是傳遞指標?Go函式指標
- Linux/Unix shell 引數傳遞到SQL指令碼LinuxSQL指令碼
- 獲取url傳遞傳遞的某個引數的值
- C#引數傳遞之值引數C#
- C++引數的傳遞方式C++
- OFBiz中的引數傳遞
- 【pytest】使用parametrize將引數化變數傳遞到fixture變數
- 命令列CALL程式時傳遞數字引數總結(轉)命令列
- drf serializer 字首 get 是什麼? 如何傳遞引數?
- ajax傳遞的引數值包含單引號
- Shell學習【引數傳遞】
- JavaScript函式傳遞引數JavaScript函式
- out,ref,params引數傳遞
- 利用閉包傳遞引數