안녕하세요, 모두 선택 상자 onchange 이벤트에서 storename의 onselect 이벤트로 하나의 선택 상자에 제품 이름을로드하기 위해 내 프로젝트에서 Ajax를 사용하고 있습니다. 여기에 자바 액션 클래스에서 jsp로 목록을 가져 오기 위해 Ajax를 사용했다. Jsp 및 Action 클래스의 내 코드는 다음과 같습니다.XML 변환 문제를 해결하는 방법?
<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();
}
내 액션 클래스에 다음 패키지를 가져 왔습니다.
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Text;
import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import 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 썬 고유의 API이며,
C 릴리스에서 제거 될 수 있습니다 : \ 사용자 데스크톱 \ \ 업데이트 \ 프로젝트 \ SRC \ 주 \ 자바 \ 닷컴 AjaxAction.java \ 행동 \ : [199,32] co.kr에서. sun.org.apache.xml.internal.serialize.XMLSerialize r은 일 고유의 API이며,
내 프로젝트는 프런트 엔드 및 백 엔드로 MySQL 서버로 Struts2, JSP로, Hibernate3은을 사용하여 추후 릴리스에서 제거 될 수 있습니다. 이 문제를 해결할 생각이 없습니다.
누구든지이 문제를 해결할 수 있도록 도와주세요. 미리 감사드립니다 !!!.
단지 측면하지 더 가볍고 더있는 JSON 형식을 고소하지 않는 이유 flexible.S2는 소음 JSON에 대한 지원과에 쉬운을 구축있다 유연하고 사용하기 쉬운 XStream을 대체적으로 사용하십시오. –
감사합니다. UmeshAwasthi. JSON 형식을 사용하기 위해 URL을 보낼 수 있습니까? 나는이 기술에 대해 전혀 모른다. 여기에 – shiva
링크가 있습니다. 클래스 패스에 플러그인이 있어야하고 갈 준비가되었습니다. https://cwiki.apache.org/confluence/display/WW/JSON%20Plugin –