aspose file tools*
The moose likes JSP and the fly likes Help:jsp pass message to Beans, but always receive null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Help:jsp pass message to Beans, but always receive null" Watch "Help:jsp pass message to Beans, but always receive null" New topic
Author

Help:jsp pass message to Beans, but always receive null

Kin Charles
Greenhorn

Joined: Oct 25, 2007
Posts: 4
Hi, all. I need your help to find the problem of below codes.

Actually I just want to input a message in a form and then pass the message to the javaBean.

(1) the form input: 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) the jsp receive the parameter and get feedback from javaBean: 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) the javaBeans: 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();
}
}
}


When it works, this.getXpin() always is null.
Why and how to sort out the problem?

Thank you.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"kingsz1",
Please check your private messages.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Kin Charles
Greenhorn

Joined: Oct 25, 2007
Posts: 4
Originally posted by Ben Souther:
"kingsz1",
Please check your private messages.


I had changed the display name.

Anyone can help my problem?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

"kingsz charles", please check your messages again.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help:jsp pass message to Beans, but always receive null