how can add new line character into ajax response for java

Ads
 

how can add new line character into ajax response for java

i want to populated brand drop-down list and state drop-down list by changing on country drop-down list i mean according to country name there will be change in state names groups and brand name groups too... meaning that change in a single drop-down list changes into two dropdown list i hv donw this but i want both drop down will be in a new line how can i do this i m showing my codes here please help me

country.jsp

<%@page import="java.sql.*"%>
 <html>
      <head>  
      <script language="javascript" type="text/javascript">  
                          var xmlHttp  
                          var xmlHttp
                          function showState(str)
                              {
                                  xmlHttp=GetXmlHttpObject();
                                  if(xmlHttp==null)
                                      {
                                       alert ("Browser does not support HTTP Request")
                                       return
                                      }

                                  var url="State.jsp";
                                  url +="?count=" +str;

                                  xmlHttp.onreadystatechange = stateChange;
                                    xmlHttp.open("GET", url, true);
                                  xmlHttp.send(null);
                             }
                         function stateChange()
                                {   
                                  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
                                      {   
                                        document.getElementById("state").innerHTML=xmlHttp.responseText


                                      }   
                               }
                         function GetXmlHttpObject()
                             {
                                     var xmlHttp=null;
                                     try
                                     {
                                         xmlHttp=new XMLHttpRequest();
                                     }
                                     catch(e)
                                     {
                                         //Internet Explorer
                                         try
                                          {
                                                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                                          }
                                         catch (e)
                                          {
                                                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                                          }
                                    }
                                return xmlHttp;
                            }
            </script>  
      </head>  
      <body>  
     <form action="StateSub.jsp" >
      <select name='country' onchange="showState(this.value)">  
            <option value="none">Select Country</option>  
    <%
                 String id="";
                 String name= "";
                 Class.forName("com.mysql.jdbc.Driver").newInstance();  
                 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shoppingcart","root","rat");  
                 Statement stmt = con.createStatement();  
                 ResultSet rs = stmt.executeQuery("Select * from country");
                 while(rs.next())
                 {
                 id=rs.getString(1);
                 name=rs.getString(2);
     %>
                    <option value="<%=id%>"><%=name%></option>  
      <%
                }

     %>
      </select>  

      <br>  
      <div id='state'>  
      Enter state
      <select name='state' >  
      <option value='-1'></option>  
      </select>  

      Enter brand
       <select name='brand' >  
      <option value='-1'></option>  
      </select>  
      </div> 


      <input type="submit"/>

      </form>
      </body> 
      </html>


state.jsp

    <%@page import="java.sql.*"%>

 <%
String country=request.getParameter("count"); 
 System.out.println("State"+country);
 String buffer="Enter state<select name='state' ><option value='-1'>Select  state</option>";  
 try
  {
         String sid="";
         String snam="";
          String bid="";
         String bnam="";


         Class.forName("com.mysql.jdbc.Driver").newInstance();  
         Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/shoppingcart","root","rat");  
         Statement stmt = con.createStatement();  
         ResultSet rs = stmt.executeQuery("Select * from state where countryid='"+country+"' ");  
           while(rs.next())
           {
                sid=rs.getString(1);
                snam= rs.getString(3);
                buffer=buffer+"<option value='"+sid+"'>"+snam+"</option>";  
           }  
         buffer=buffer+"</select>"; 




 String buffer1="Enter brand<select name='brand' ><option value='-1'>Select  brand</option>";  


         Statement stmt1 = con.createStatement();  
         ResultSet rs1= stmt1.executeQuery("Select * from try where countryid='"+country+"' ");  
           while(rs1.next())
           {
                bid=rs1.getString(2);
                bnam= rs1.getString(1);
                buffer1=buffer1+"<option value='"+bid+"'>"+bnam+"</option>";  
           }  
         buffer1=buffer1+"</select>"; 
          response.getWriter().print(buffer+"::\\\\n"+buffer1);

  }
 catch(Exception e)
  {
     System.out.println(e);
  }

 %>


StateSub.jsp



    <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'StateSub.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>

  <body>
  <%
  String s1=request.getParameter("country");
  String s2=request.getParameter("state");

  String s3=request.getParameter("brand");
  System.out.println(s1+" : "+s2+" : "+s3);
  out.println(s1+" : "+s2+" : "+s3);
   %>
  </body>
</html>
View Answers

Ads









Related Tutorials/Questions & Answers:
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want... down will be in a new line how can i do this i m showing my codes here please... { xmlHttp=new XMLHttpRequest
how can add new line character into ajax response for java
how can add new line character into ajax response for java   i want... down will be in a new line how can i do this i m showing my codes here please... { xmlHttp=new
Advertisements
add new package java
add new package java  How to add new package in Java
How can i read a file from nth line onwards in java
How can i read a file from nth line onwards in java  Hi, I need to read a file content from its nth line onwards till end. How can i implement it in java. Regards, Chinnu
How to write file text In New Line
text in new line in Java program. How to write the syntax for this with example... text in a new line. For finds examples or syntax please visit the link How to write file text in New line in Java
How to insert new line after every space in java
How to insert new line after every space in java  Hii Sir, I have a string with values 69 17 17 16 2 1 1 26 26 56 like this .Now as per my need i have to put all these values into new lines on getting space
How can you add elements of two arrayLists in java?
How can you add elements of two arrayLists in java?  if you have an arrayList of tempArr = [hi, my, name, is, john] and another arrayList..., is d, john e] how do you go about
How to read big file line by line in java?
Learn how to write a program in java for reading big text file line by line In this tutorial I will explain you how you can read big file line by line... legacy data and add it to your new database system. Example discussed here
How to write file by line in Java
in a new line. How to use Write To File By Line in Java programs...How to write file by line in Java  How to write file by line in Java   Hi, For Write to a file by line using java programming language we
How to get the unicode of japanese character input in java
How to get the unicode of japanese character input in java  Good Evening sir/madam; I am trying to create an application in java which needs to show the japanese character on frame and need to get the japanese string from
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
Java - How to read a string line per line
Java - How to read a string line per line  Java - How to read... to read the big String line per line? Is there any API available in Java... it line by line. This way you can reduce the memory usage of the application
How to add BigDecimal in Java?
How to add BigDecimal in Java?  Hi, I have two BigDecimal variables. I want to add these two values. How to add BigDecimal in Java? Thanks   Hello, I will show you how you can add two BigDecimal? Suppose you have
Write Text To File In New Line.
Write Text To File In New Line. In this tutorial you will learn how to write text into file in a new line. When you are writing in a file you may be required to finish the line and want to write the other text in a new line
how can i add hibernate plugin to eclipse?
how can i add hibernate plugin to eclipse?  how can i add hibernate plugin to eclipse
BufferedReader in Java
, arrays, lines and File Line by line. It also reads text from a character... will show how to read line by line data from a file using BufferedReader...() - This method skips character. Video: How to read data from file
character as command line arguments
character as command line arguments  public class testing { public static void main(String args[]) { char a; a=args[0]; System.out.println("character is:"+a); } } what will be the above program output
How Can I get ArrayList of Data from jsp with ajax request
How Can I get ArrayList of Data from jsp with ajax request  Hi, I retereved 5 Employee Record of Data from Struts Action class to jsp with ajax response. But I don't how how can reterve this dynamic 5 employee records
how to add database in Java Applet
how to add database in Java Applet  hi every java master or Java Professional my name is vincent i'm java beginners hope u all can ,tech me how to add database in Java Applet below this code is my applet source code . thank
How to add dynamic table in java
How to add dynamic table in java  How to add dynamic table in java... JTableDatabase { public static void main(String[] args) { Vector columnNames = new Vector(); Vector data = new Vector(); JPanel p=new JPanel(); try { Class.forName
AJAX Line
AJAX Line       AJAX Community with a blog, forum and tutorials Read full Description
How to add google page in my webpage using jquery ajax.
How to add google page in my webpage using jquery ajax.  Hi, I... not open on my browser. how google page will load using ajax. thanks...://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text
How can i display the distance of a line drawing randomly?
How can i display the distance of a line drawing randomly?  How can i display the distance of a line drawing randomly
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new... new fields dateOfJoining and address. Then using the given query, we can add the new columns to the existing table. Alter Table employee add (dateOfJoining date
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new... new fields dateOfJoining and address. Then using the given query, we can add the new columns to the existing table. Alter Table employee add (dateOfJoining date
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new... new fields dateOfJoining and address. Then using the given query, we can add the new columns to the existing table. Alter Table employee add (dateOfJoining date
how to add new column before two column in sql.
how to add new column before two column in sql.  how to add new... new fields dateOfJoining and address. Then using the given query, we can add the new columns to the existing table. Alter Table employee add (dateOfJoining date
how can i use ajax and jquery in netbeans ide
how can i use ajax and jquery in netbeans ide  i am using .net here we hav to download ajax controls and if i use netbeans ide and uses ajax control so from where i can get these controls.also i want to know which struct book i
How to pass command line arguments in Java?
How to pass command line arguments in Java?  Hi, In a Java program I... it in a programming. How to pass command line arguments in Java? Share me the sample code. Thanks   Hi, You can use the String[] args of the main function in Java
how can i draw line between two panel contaning circle and line between their center?
how can i draw line between two panel contaning circle and line between their center?   how can i draw line between two panel contaning circle and line between their center
Java Read File Line By Line, Video Tutorial of Java Read File Line By Line
can write code to read a text file in Java line by line". Steps... method of reading file in Java line by line The java.util.Scanner class can also... a program in Java programming language to read a text file line by line. The "

Ads