Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > JSP Basics
Password Reminder
| FAQ | Members List | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.....

<head><title>Add Page</title></head>
<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" />

<jsp:useBean id="country" class="com.Country" scope="request" />
<jsp:setProperty name="country" property="*" />


<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") %>

<input type="Submit" value="Save" />
<input type="Submit" value="Cancel">

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

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
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

All times are GMT -4. The time now is 06:32 AM.

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