Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i'm Writing code like this, in Test.JSP
<html>
<head>
XML
<script>
         $(document).ready(function() {
        $('#country').change(function(event) {
        var $country=$("select#country").val();
           $.get('ActionServlet',{countryname:$country},function(responseJson) {
               var $select = $('#states');
               $select.find('option').remove();
               $.each(responseJson, function(key, value) {
                   $('<option>').val(key).text(value).appendTo($select);
                    });
            });
        });
    });
</script>

XML
</head>
    <body>
        <h1>AJAX calls to Servlet using JQuery and JSON</h1>
Select Country:
<select id="country">
<option selected="selected">Select Country</option>
<option value="India">India</option>
<option value="US">US</option>
</select>
<br/>
<br/>
Select State:
<select id="states">
<option selected="selected">Select State</option>
</select>

</body>
</html>


and in servlet

----------------------------------------------------------

C#
public class ActionServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;


    public ActionServlet() {
        // TODO Auto-generated constructor stub
    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String country=request.getParameter("countryname");
        Map<String, String> ind = new LinkedHashMap<String, String>();
        ind.put("1", "New delhi");
        ind.put("2", "Tamil Nadu");
        ind.put("3", "Kerala");
        ind.put("4", "Andhra Pradesh");

        Map<String, String> us = new LinkedHashMap<String, String>();
        us.put("1", "Washington");
        us.put("2", "California");
        us.put("3", "Florida");
        us.put("4", "New York");

        Map<String, String> reset = new LinkedHashMap<String, String>();
        reset.put("1", "Select State");

        String json = null ;
        if(country.equals("India")){
            json= new Gson().toJson(ind);
        }
        else if(country.equals("US")){
            json=new Gson().toJson(us);
        }
        else if(country.equals("Select Country"))
        {
            json=new Gson().toJson(reset);
        }
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(json);


    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

    }

}



in Web.xml i'm writing like this,
XML
<servlet>
    <servlet-name>ActionServlet</servlet-name>
    <servlet-class>Test.Sales.ActionServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>ActionServlet</servlet-name>
    <url-pattern>/ActionServlet/*</url-pattern>
  </servlet-mapping>



So, My problem is when i keep my Test.Jsp File in Web Pages Folder, It is working file.
But if i add a folder and place this Test.jsp file there, I'm not getting the result.

I'm using netbeans. ANd the requirement is to get the state based on the selected Country.

Pls do the needful
Posted
Updated 24-Dec-13 21:28pm
v2
Comments
OriginalGriff 25-Dec-13 3:28am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900