Hi,
i'm Writing code like this, in Test.JSP
<html>
<head>
<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>
</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
----------------------------------------------------------
public class ActionServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public ActionServlet() {
}
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 {
}
}
in Web.xml i'm writing like this,
<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