我要从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 herefp.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传来的xpin 的字符到 getpinbal() ?
各位老大请看看是什么问题?谢谢。

解决方案 »

  1.   

    check code bellow:<h3 >JSP Page </h3 >
    <%--
    The pin is:  <%= eCoinClient.getXpin() % >  <br/ >
    The balance is:  <%= eCoinClient.getXbal() % >  <br/ >
    --% > suggest that modifying like this: <h3 >JSP Page </h3 >
    <%--
    The pin is:  <%= gpin.getXpin() % >  <br/ >
    The balance is:  <%= gpin.getXbal() % >  <br/ >
    --% > 
      

  2.   

    你的JavaBean 没有序列化。
    你把JavaBean序列化就可以了! 
      

  3.   

     getpinbal.jsp 中
    <jsp:setProperty name="gpin" property="xpin" / >
    这段有问题吧!
    你不如这样:
     在这页面中定义个另外的量,将XPIN赋给他,然后再将上句话中的PROPERTY=你定义的量,应该就可以了!
      

  4.   

    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/ > 看了你这代码不晓得你要搞什么!!
      

  5.   

    <% gpin.setpinbal();  %>试试!