usha kotha wrote:
Toni Montero wrote:Your call to getJson is not valid, you must put action name, after this parameters and function (data....etc
Put here your js method, please.
here is my js method
function ajaxCallForContacts(value)
var formInput= 'business='+value;
var options=''; //variable para poner los valores de subfamilia
options += '<option selected value="0">hiringManager</option>';
$("#hiringManager").html(options);
options = '';
$.getJSON('JobActionJson?action=json&business=ADP', function(data) {
alert(data);
options += '<option selected value="0">ClientContacts</option>';
$.each(data.listOfCliContacts, function(i,item){
options += '<option value="' + item.firstName + '">' + item.lastName + '</option>';
});
$("#hiringManager").html(options);
});
Hi Toni Montero ,
Here im shifted to
servlets with ajax.....
here im facing problem in configuring servlets with struts2...
here im attaching my code please have a look over it and give me some solution
*******************struts.xml********************
here in this xml im getting error
( The content of element type "package" must match "(result-
types?,interceptors?,default-interceptor-ref?,default-action-
ref?,default-class-ref?,global-results?,global-exception-
mappings?,action*)".
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="JobAction" class="com.itpc.jats.struts.model.JobAction">
<result name="input">/jobs.jsp</result>
<result name="success">/NoSourcer.jsp</result>
</action>
</package>
<package name="struts-default" abstract="true">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
<interceptor name="servletConfig" class="org.apache.struts2.interceptor.ServletConfigInterceptor"/>
</interceptors>
</package>
</struts>
************web.xml************
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>JATS</display-name>
<servlet>
<description>
</description>
<display-name>Servletretrieve</display-name>
<servlet-name>Servletretrieve</servlet-name>
<servlet-class>com.itpc.jats.struts.model.Servletretrieve</servlet-class>
</servlet>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
</web-app>
************Jobs.jsp************
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jobs</title>
<link rel="stylesheet" type="text/css" href="style.css">
<sx:head parseContent="true" />
<script type="text/javascript" src="jquery-1.7.2.js"></script>
<script language="JavaScript" type="text/javascript">
function toggle5(showHideDiv, switchImgTag) {
var ele = document.getElementById(showHideDiv);
var imageEle = document.getElementById(switchImgTag);
if(ele.style.display == "block") {
ele.style.display = "none";
imageEle.innerHTML = '<img src="images/plus.png">';
}
else {
ele.style.display = "block";
imageEle.innerHTML = '<img src="images/minus.png">';
}
}
$(document).ready(function () { // Make sure the elements are loaded on the page
// Listen for a click event on the button
alert("ready");
$('#business').onchange(ajaxCallForContacts);
alert("afterready");
});
function ajaxCallForContacts()
{
alert("hi");
var business=document.getElementById("business");
var selecteddata = business.options[business.selectedIndex].value;
alert(selecteddata);
$.ajax("http://localhost:8082/JATS/Servletretrieve?business=selecteddata", {
data: { "get" : "runfunction", "action" : "json" },
method: "GET",
success: function (response) {
var items = [];
$.each(response, function(key) {
var val = response[key].url;
alert(val+key);
});
}
});
}
</script>
</head>
<body>
<div class="title_bg" style="background: #554D4E; color: #fff;">Jobs
Details</div>
<div
style="color: black; font-family: arial; font-size: 11px; font-style: italic; text-align: left; margin-top: 10px; margin-left: 186px;">
Fields marked with<span style="color: red"> * </span>are mandatory
</div>
<form name="frm" action="JobAction" method="post">
<div class="wrap2" style="width: 1000px; margin: 10px auto;">
<div style="width: 500px; float: left;">
<div
style="background: none repeat scroll 0% 0% rgb(115, 107, 108); text-align: left; z-index: 1; position: relative; margin-left: 48px; width: 395px;"
class="title_bg">
<div style="float: left;">Basic Information</div>
<div id="titleTextImg" style="float: right; margin-left: 50px;">
<a href="javascript:toggle5('contentDivImg', 'imageDivLink');"
id="imageDivLink"><img src="images/minus.png"></a>
</div>
<div style="clear: both;"></div>
</div>
<div style="clear: both;"></div>
<div id="contentDivImg"
style="border-bottom: 2px solid #CCCCCC; border-left: 2px solid #CCCCCC; border-radius: 10px 10px 10px 10px; border-right: 2px solid #CCCCCC; display: block; margin: -8px auto 0; width: 400px; z-index: 0;">
<table align="center"
style="font-family: sans-serif; font-size: small; font-style: normal; padding: 15px; width: 358px; position: relative; right: 32px;">
<tbody>
<tr>
</tr>
<tr>
<s:select label="Business or Business Id" name="business" onchange="ajaxCallForContacts();" id="business"
headerKey="Select" headerValue="Select" list="ListOfClients"
listKey="%{business}" listValue="%{business}" required="true"
style="border:1px solid #ccc; background:#fff; width:165px;"/>
</tr>
<tr>
</tr>
<tr>
<s:select label="Hiring Manager" name="hiringManager" id="hiringManager"
headerKey="Select" headerValue="Select"
list="ListOfCliContacts" listKey="%{firstName}"
listValue="%{firstName}" required="true"
style="border:1px solid #ccc; background:#fff; width:165px;" />
</tr>
<tr>
</tr>
<tr>
<td align="center" style="padding-top: 10px;"><input
type="submit" name="submit" align="center" value="Save"
class="title_bg" style="width: 54px;" /></td>
</tr>
****myservlet *****
/**
* Servletretrieve
* @version 1.1
* @copyright iTPC
*/
package com.itpc.jats.struts.model;
import java.io.IOException;
import java.lang.String;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import net.sf.json.JSONArray;
import org.w3c.dom.Document;
/**
* Servlet implementation class Servletretrieve
*/
public class Servletretrieve extends HttpServlet {
/**
* @see HttpServlet#HttpServlet()
*/
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String business = request.getParameter("business");
JsonObjectInsertion obj = new JsonObjectInsertion();
JSONArray jsonArray;
try {
((JsonObjectInsertion) obj).jsonObjectGenerated(response);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
could you please help me out in configuring servlets with struts2 as early as possible...................