Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
| Search | Today's Posts | Mark Forums Read
JSP Basics Beginning-level questions on JSP. More advanced coders should post to Pro JSP.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the JSP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 1st, 2006, 04:22 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default pass variable from jsp to java file

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.....





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
pass variable in the same java file ypsmag Java Basics 0 November 1st, 2006 04:15 AM
call java file method to do something in JSP ypsmag JSP Basics 1 October 11th, 2006 01:43 PM
pass java variable to xsl variable kathy1016cats XSLT 1 June 14th, 2006 06:23 PM
how to pass an array in jsp to other js? lch Javascript 5 April 18th, 2006 06:56 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.