こんにちは、プロジェクトで Ajax を使用して、選択ボックスの onchange イベントで storename の onselect イベントを使用して、1 つの選択ボックスに製品名をロードしています。ここでは、Java アクション クラスから JSP へのリストを取得するために Ajax を使用しました。Jsp および Action クラスの私のコードは次のとおりです。
<s:label value="Store Name : *" />
<s:select name="storeName" list="storeList" onchange="loadProduct(this.value)" listKey="storeId" listValue="storeName" headerKey="-1" headerValue="Select the Store" />
<s:label value="Product Name : *" />
<s:select name="productName" list="productList" listKey="productId" listValue="productName" />
function loadProduct(id){
var URL = "AjaxPopMyCycle.action?storeName="+id;
ajaxEditFunctionCall(URL);
}
function ajaxEditFunctionCall(URL){
try{
xmlHttp=new XMLHttpRequest();
}catch (e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch (e){
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4){
if (xmlHttp.status == 200) {
if(xmlHttp.responseXML != null ){
showMessage(xmlHttp.responseXML);
}
}
}
}
xmlHttp.open("GET", URL, true);
xmlHttp.send(URL);
}
function showMessage(errorDisplayXML){
var checklist=document.Add.productName;
checklist.options.length=0;
if(xmlHttp.readyState==4){
if(errorDisplayXML.getElementsByTagName("rootElement")[0]!=null){
var rootElement = errorDisplayXML.getElementsByTagName("rootElement")[0];
var location = rootElement.getElementsByTagName("Message");
var locArr = location[0];
var locArr = " ";
var tempArr;
var tempArr1;
for(var i=0; i<location.length; i++){
tempArr = "";
tempArr1 = "";
locArr = location[i];
tempArr = locArr.getElementsByTagName("productId")[0].firstChild.nodeValue;
tempArr1 = locArr.getElementsByTagName("productnName")[0].firstChild.nodeValue;
checklist.options[i]= new Option(tempArr1,tempArr);
}
}else{
alert("errorDisplayXML Contains NULL");
}
}
}
結果を取得し、次のように XML にロードするための Action クラスの次のコード。
detailedList には、データベースからストアに関連する製品のリストが含まれています。
public String getDetails(List detailedList)throws Exception{
Element tempElem = null,
rootElem = null;
Text textElem = null;
document=new org.dom4j.dom.DOMDocument();
rootElem = document.createElement("rootElement");
Element errorElement = null;
List saveList = new ArrayList();
saveList = detailedList;
System.out.println("DetailedList:"+saveList.size());
if(saveList.size()>0){
try {
for(int i=0;i<saveList.size();i++){
Product aproduct = (Product )saveList.get(i);
errorElement = document.createElement("Message");
tempElem = document.createElement("productId");
textElem = document.createTextNode(aproduct .getProductId());
tempElem.appendChild(textElem);
errorElement.appendChild(tempElem);
tempElem = document.createElement("productName");
textElem = document.createTextNode(aproduct.getProductName());
tempElem.appendChild(textElem);
errorElement.appendChild(tempElem);
rootElem.appendChild(errorElement);
}
}catch (Exception e) {
tempElem = document.createElement("Message");
return parseToString(tempElem);
}
return parseToString(rootElem);
}
public String parseToString(Element node) throws Exception {
OutputFormat format = new OutputFormat();
StringWriter stringOut = new StringWriter();
XMLSerializer serial = new XMLSerializer(stringOut,format);
serial.asDOMSerializer();
serial.serialize(node);
return stringOut.toString();
}
アクション クラスに次のパッケージをインポートしました。
org.w3c.dom.Document をインポートします。
org.w3c.dom.Element をインポートします。
org.w3c.dom.Text をインポートします。
com.sun.org.apache.xml.internal.serialize.OutputFormat をインポートします。
com.sun.org.apache.xml.internal.serialize.XMLSerializer をインポートします。
過去 3 週間、正しい機能で問題なく動作します。
しかし、サーバーで次のエラーメッセージをコンパイルして表示していません。
C:\Users\Desktop\Updated\Project\src\main\java\com\action \AjaxAction.java:[199,5] com.sun.org.apache.xml.internal.serialize.XMLSerializer は Sun 独自の API であり、将来のリリースで削除される可能性があります
C:\Users\Desktop\Updated\Project\src\main\java\com\action \AjaxAction.java:[199,32] com.sun.org.apache.xml.internal.serialize.XMLSerialize r は Sun 独自の API です。将来のリリースで削除される可能性があります
私のプロジェクトでは、Struts2、Jsp、Hibernate3 をフロント エンドとして、Mysql サーバーをバック エンドとして使用しています。この問題を解決する方法がわかりません。
誰でもこの問題を解決するのを手伝ってください。前もって感謝します!!!。