i having problem to pass the value capture from JSP text box into java method....
coz i very new in java and jsp...so i try to know this for create a very simple project.... i have create 2 attribute ...that is CountryName and CountryPopulation...i using jsp to create the user interface ....the interface got 2 text box, CountryName and CountryPopulation.....
I need to store this 2 value after the user key in from the text box....another thing is i need to use java bean in this simple project...
i already create the javamethod in java file and jsp file for the interface, but i still having problem....when i click save button i still cannot run the storeData method in java.....
can any one help me to check whether is my coding having a big problem.....
-----------------------------------
add.jsp
---------------------------------
Code:
<html>
<head><title>Add Page</title></head>
<body>
<form action="add2.jsp" method="Get">
<p><b>Country Name :</b><input type="text" name=countryName property="countryName" /><br>
<p><b>Population :</b><input type="text" name=countryPopulation /></p>
<input type="submit" value="Save" name="save"/>
<input type="Submit" value="Cancel" />
</form>
</body>
</html>
----------------------------
add2.jps
----------------------------
Code:
<jsp:useBean id="country" class="com.Country" scope="request" />
<jsp:setProperty name="country" property="*" />
<html>
<head><title>add2</title></head>
<body>
<h1>Comfirm to sava the data</h1>
<jsp:setProperty name="country" property="countryName" />
<b>Country Name: </b><%= request.getParameter("countryName") %><br>
<jsp:setProperty name="country" property="countryPopulation" />
<b>Country Population: </b><%= request.getParameter("countryPopulation") %>
<br><br><br>
<input type="Submit" value="Save" />
<input type="Submit" value="Cancel">
<br>
</form>
</body>
</html>
----------------------------------
Country.java
---------------------------------
Code:
package com;
import com.db4o.*;
import java.io.*;
public class Country {
public String countryName;
public int countryPopulation;
final static String filename = "C:\\abc.yap";
public Country(String countryName, int countryPopulation){
this.countryName = countryName;
this.countryPopulation = countryPopulation;
}
public Country(){
}
public String getCountryName(){
return countryName;
}
public void setCountryName(String countryName){
this.countryName = countryName;
}
public int getCountryPopulation(){
return countryPopulation;
}
public void setCountryPopulation(int countryPopulation){
this.countryPopulation = countryPopulation;
}
public void setData(String countryName){
new File(filename).delete();
ObjectContainer db = Db4o.openFile(filename);
Country c1 = new Country();
}
}
---------------------------------------------------------------------------------
add.jsp will display the layout and let user key in the countryName and countryPopulation.....after user click on save --> it will go to add2.jsp......
in add2.jsp it will display the value user key in...if the user confirm to save the data it will come display a message tell the user "you are successfully save"....i having problem in the last part ..... the confirm save data that part.....
how i pass the countryName and countryPopulation into the Country.java file...i need to pass the countryName and countryPopulation value into the setData method in java.....after i click on save, it will run the setData method....
it is possible to do this.....
Thank You.....