Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet Retriving value from dropdown list nad disply it in other page
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


pradeep naidu
Retriving value from dropdown list nad disply it in other page
5 Answer(s)      4 years ago
Posted in : JSP-Servlet


Hello,

I have a dropdownbox on my webpage and a map which contains a marker, and that marker contains a button, on click of that button i need to get the name of the selected value from the dropdown list and dispaly it to on the next page.

i used request.getParameter("") but its not working its printing "null".

So could you please help me out with this!!

thanks, Pradeep


Advertisement
View Answers

January 13, 2011 at 12:44 PM


Hi Friend,

Try this:

1)combo.jsp:

<html>
<form method="post" action="selectedValue.jsp">
Select Programming Language:
<select name="lang">
<option value="C/C++">C/C++</option>
<option value="C#">C#</option>
<option value="Java">Java</option>
<option value="Perl">Perl</option>
<option value="Python">Python</option>
</select><br>
<input type="submit" value="Submit"><br>
</form>
</html>

2)selectedValue.jsp:

<%
String selectedValue=request.getParameter("lang");
out.println("Selected Value is: "+selectedValue);
%>


January 13, 2011 at 12:44 PM


Hi Friend,
Try this:

1)combo.jsp:

<html>

<form method="post" action="selectedValue.jsp">
Select Programming Language:
<select name="lang">
<option value="C/C++">C/C++</option>
<option value="C#">C#</option>
<option value="Java">Java</option>
<option value="Perl">Perl</option>
<option value="Python">Python</option>
</select><br>
<input type="submit" value="Submit"><br>
</form>

</html>

2)selectedValue.jsp:

&lt;%
String selectedValue=request.getParameter("lang");
out.println("Selected Value is: "+selectedValue);
%&gt;


January 13, 2011 at 2:07 PM


but my problem is i have the button on my marker and the dropdownlist is on the webpage so how to link both button and dropdownlist

can u please help me on this issue



January 14, 2011 at 3:21 PM


Hi Friend,

Post your code.

Thanks



January 17, 2011 at 11:45 AM


ok iam posting my code

This is my 1.jsp file

<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="java.sql.*" %>

        <%!
            int i=1;
            Connection connection = null;
            boolean foundResults = false;
            ResultSet set = null;
            Statement statement = null;
            String city;
            String ip;
            String sysname;
            String sess;

        %>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml"> 

  <head> 

    <meta http-equiv="content-type" content="text/html; charset=utf-8"/> 

    <title>Google Maps API Sample</title>

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAAPDUET0Qt7p2VcSk6JNU1sBSM5jMcmVqUpI7aqV44cW1cEECiThQYkcZUPRJn9vy_TWxWvuLoOfSFBw" type="text/javascript"></script>

    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key=ABQIAAAA1XbMiDxx_BTCY2_FkPh06RRaGTYH6UMl8mADNa0YKuWNNa8VNxQEerTAUcfkyrr6OwBovxn7TDAH5Q"></script>                                 

    <script type="text/javascript"> 

    var map; 

    var geocoder;

    var address=sel.options[sel.selectedIndex].value;
    document.write(address);

    //sess = address;
    //session.setAttribute("sess1",sess);

    function createMarker(point,html,what) 

    {

        var marker = new GMarker(point,{id:what, name:"foo", description:"baz"});

        GEvent.addListener(marker, "mouseover", function() {

        marker.openInfoWindowHtml(html);

        });

        return marker;

     }

    function initialize() 
    { 

        map = new GMap2(document.getElementById("map_canvas")); 

        map.addControl(new GLargeMapControl());

        map.addControl(new GScaleControl());

        map.setCenter(new GLatLng(79, 0, true), 8); 

        map.addControl(new GMenuMapTypeControl(true,false));

        var point1 = map.getCenter();

        var marker = createMarker(point1,'<img src="printers-for-wire-and-network-elements-marking-43844.jpg" width="100" height="100">',"this")

        map.addOverlay(marker);

        geocoder = new GClientGeocoder();                       

    }


    function addAddressToMap(response) { 

     map.clearOverlays(); 

     if (!response || response.Status.code != 200) { 

       alert("Sorry, we were unable to geocode that address");

     } else { 

       place = response.Placemark[0];

       point = new GLatLng(place.Point.coordinates[1], 

                           place.Point.coordinates[0]); 
        //var test = 'ajaykumar';
        //alert(test);
      var marker = createMarker(point,'<form action="/Details.jsp"><input type="image" name="b" value="click" src="printers-for-wire-and-network-elements-marking-43844.jpg" width="100" height="100"></form>',"this");

      map.addOverlay(marker); 
      marker.openInfoWindowHtml('<b>Coordinates:</b>' + place.Point.coordinates); 
     }

    }

    function showLocation(sel) 
    { 

     address = sel.options[sel.selectedIndex].value;
     geocoder.getLocations(address, addAddressToMap); 

    } 

    function findLocation(address)
    { 

     showLocation(); 

    }

    function find()
    { 

     window.open("/Details.jsp","winA","width=300,height=300,resizeable=no")

    }


 </script> 

  </head> 

  <body onload="initialize()" onunload="GUnload()" style="font-family: Arial;border: 0 none;"> 


  <form name="f1" action="#" onsubmit="showLocation(); return false;">

  <p> 
        <TABLE ALIGN="CENTER">
        <b>Search cities:</b>


        <%
            try 
            {
                Class c = Class.forName("org.postgresql.Driver");
                //out.print(c);

                connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres","postgres", "password");

                statement = connection.createStatement();               

                set = statement.executeQuery("SELECT sno,city,ip,sysname FROM test");


        %>
            <select name="htmlcombo" onchange="showLocation(this)">
        <%
            while(set.next())
            {

        %>
            <option value=<%= set.getString(2)%>> <%= set.getString(2)%> </option>

        <%  } 

        %>
            </select>

            </TABLE>

        <%

            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        %>
      </p> 

    </form>


    <div id="map_canvas" style="width: 1250px; height: 740px"></div>
    <form>
    <%
    try{
        out.print(set.getString(2));
    %>

    <%
    }
    catch(Exception e)
    {}
    %>
    </form>

  </body>

I need the selected value in my 2.jsp file on clicking of the image on the marker.

2.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="java.sql.*" %>

        <%
            int i=1;
            Connection connection = null;
            boolean foundResults = false;
            ResultSet set = null;
            Statement statement = null;
            String city;
            String ip;
            String sysname;

            //String getCity=(String)session.getAttribute("sess1");
            //out.print(getCity);

            String val=request.getParameter("htmlcombo");
            out.print(val);



            //out.print(request.getQueryString());

            try 

            {
                Class.forName("org.postgresql.Driver");

                connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres", 
                                           "postgres", "password");

                statement = connection.createStatement();               

                set = statement.executeQuery("SELECT sno,city,ip,sysname FROM test where city='"+val+"'");

                while(set.next())
                {
                    city=set.getString(2);
                    ip=set.getString(3);
                    sysname=set.getString(4);
                    out.print(city+"<br>");
                    out.print(ip+"<br>");
                    out.print(sysname+"<br>");
                    out.print("<br><br>");

                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        %>


Related Tutorials/Questions & Answers:
Retriving value from dropdown list nad disply it in other page
Retriving value from dropdown list nad disply it in other page  Hello, I have a dropdownbox on my webpage and a map which contains a marker... of the selected value from the dropdown list and dispaly it to on the next page. i
how to load value in dropdown list after selecting value from first dropdown list using javascript
how to load value in dropdown list after selecting value from first dropdown list using javascript  how to load value in dropdown list after selecting value from first dropdown list using javascript
Advertisements
help to select a value from the dropdown list
help to select a value from the dropdown list  I have a html file... from the drop down list created in a div and put it in the textbox kim... <input type="text" size="30" name="inputString" value="" id="inputString
how to use dropdown list in JSP and display value in same page
how to use dropdown list in JSP and display value in same page  I have a Dropdown list with some values say "A", "B" and "C" When the user selects one option the value must get displayed below it in the same page
how to set value of dropdown list
how to set value of dropdown list  Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a dropdown list. I want to set the dropdown list selected
how to set value of dropdown list
how to set value of dropdown list  Hello Sir, I'd solved the earlier problems somehow but now this time another problem arised when I want to pass the value from a link to a dropdown list. I want to set the dropdown list selected
getting values from dropdown list
getting values from dropdown list  I am having a dropdown list which has hardcoded values ( we need it hardcoded only and will not be populated from the database) My question is when i select a particular value it should be pass
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP  as i said i want to create 3 drop dropdown list each depend on the other and get the options from
3 dropdown list from the database using JSP
3 dropdown list from the database using JSP  Hi, I'm new to JSP I want to create 3 dropdown list each depend on the other and get the options from the database using JSP
populating one dropdown box depending on the value of other using jsp
populating one dropdown box depending on the value of other using jsp ... on the value of other using the below table country name state and city name should load in dropdown box one after the other CREATE TABLE CITY_MASTER( CITYID BIGINT
How to display content in same page while selecting fron dropdown list
How to display content in same page while selecting fron dropdown list ... dropdownlist in jsp page.If i select any value in that list(for eg-rollno),then it want to display all records from table specific to that rollno in that same
DropDown list
values into dropdown list. 1)country.jsp: <%@page import="java.sql.*"%>...DropDown list  how to get mysql database values into dropdown usign...;option value="none">Select</option> <% Class.forName
How to automatically change the value of the textbox based on the dropdown list?
How to automatically change the value of the textbox based on the dropdown list?  I want to know how to automatically change the value of price and the quantity text boxes. Here is my code: <%@ page import="java.sql.
JSP Get Data Into Dropdown list From Database
JSP Get Data Into Dropdown list From Database In this section we will discuss about how to fetch data dynamically into the dropdown list in JSP... data from the database and set it into the dropdown list in JSP using MySQL
How to display content in same page while selecting fron dropdown list
How to display content in same page while selecting fron dropdown list  Thanks for your suggesstion.but Please provide me coding by using only one dropdownlist in javascript or jquery.Thanks in advance
how to add data dynamically from database into a dropdown list in a jsp
how to add data dynamically from database into a dropdown list in a jsp ... and department fields also.I have a create an jsp page in which there should 2 drop down list.In that first list is for department and the 2nd list for the names
How to access Contacts from gmail using LDAP in JSP dropdown list
How to access Contacts from gmail using LDAP in JSP dropdown list  HI, I am creating a JSP page in which i have to make a dropdown box, and access gmail contacts in that drop downlist using LDAP. Can any one plz help me out
dropdown list in jsp
dropdown list in jsp  hai, i have static dropdown list.. i want to get the selected value in string variable without jsp regards asha
struts dropdown list
struts dropdown list   In strtus how to set the dropdown list values from database ? I have a ArrayList object and set this object in dropdown jsp page using struts ? please send me jsp code... sample code: **Action
Not retriving the validations from validation.xml - Struts
Not retriving the validations from validation.xml  I have create the file called register.jsp    LoginID: Password: when i
. Display JavaScript dropdown selected value
value from dropdown box? I am using javascript.   <html> <... you select any value from list, alert will display that. In var... document.getElementById("dropdown").value .you can show this value in alert or any other
Retrieval of Dropdown list
, the corresponding value of A1, list of name corresponding to A1 wil be displayed in another...Retrieval of Dropdown list  Hi frnds... Am having problem with the below code... I have retrieved data from the mysql database into dropdownlist
dropdown list in jsf
dropdown list in jsf  I want to add a list box to display the country name from the lists on all countries.When I select for e.g India then in the second list box it will display the states related to India only and the flow
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
How to invoke other java class by selecting from dropdown menu and subsequently clicking button in java swing application
How to invoke other java class by selecting from dropdown menu... a dropdown menu to choose type of report and then click on submit button.On clicking submit button should show the user various textfields on the same panel from
how can i send a mail to a particular user from a many user dropdown list in jsp
how can i send a mail to a particular user from a many user dropdown list in jsp  how can i a sent a user question to a particular person from a drop down list in jsp
retriving image from database - JSP-Servlet
retriving image from database  how to retrive image from mysql database by using servlet programming  Hi Friend, Please visit the following link: http://www.roseindia.net/servlets/retreiveimage.shtml Thanks
jsp- database dependent dropdown list
jsp- database dependent dropdown list   i want 2 dropdown list 1- CLASS 2-SECTION both are should come from database. and if i select a class suppose class a the corresponding section dropdown list should retrieve the section
dropdown list and text fields in php
dropdown list and text fields in php  How could I use php to populate text fields by selecting a name of a business from dropdown list? Those text... number, description, and opening times from a mysql database. If you can, post
loading value into combo box by selecting value from other combo box - JSP-Servlet
loading value into combo box by selecting value from other combo box  ... is that as i select state from state_combo_box,then the next combo box is dynamically... in same JSP page. please help me
Advertisements
 

 

 

DMCA.com