[/WEB-INF/src/web/ajax/AjaxAction.java]
package web.ajax;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.*;
import com.opensymphony.xwork2.ActionSupport;
public class AjaxAction extends ActionSupport implements ServletRequestAware, ServletResponseAware {
private HttpServletRequest request;
private HttpServletResponse response;
private Logger logger = Logger.getLogger(this.getClass());
public String autoComplete() throws Exception {
try{
logger.info("autoComplete start");
String[] wordArr = {"acrobat“, "adobe“, "bmw",
"brave“, "cbs“, "cnn",
"heaven“, "html“, "kbs",
"key“, "net“, "news",
"queen“, "quick“, "soup",
"super“, "ufo“, "usb",
"work“, "wow“, "zebra",
"zenith"};
StringBuffer xmlStr = new StringBuffer("");
boolean isTitleExist = false;
//실제업무에서는 비지니스 레이어에서 XML String을 구현한다.
//String xmlStr = ajax.getAutoCompleteTitleList(boardVO);
xmlStr.append("<?xml version=\"1.0\" encoding=\"EUC-KR\"?>");
xmlStr.append("<words>");
for(int i = 0; i < wordArr.length ; i++){
if(wordArr[i].indexOf(request.getParameter("word")) != -1){
xmlStr.append("<word>");
xmlStr.append(wordArr[i]);
xmlStr.append("</word>");
isTitleExist = true;
}
}
xmlStr.append("</words>");
//logger.info("request.getParameter(\"title\") : " + request.getParameter("title"));
logger.info("xmlStr.toString() : " + xmlStr.toString());
if(isTitleExist){
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(xmlStr.toString());
}else{
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
logger.info("forward :" + request.getParameter("forward"));
logger.info("autoComplete end");
return null;
}catch(Exception e){
logger.info("Error : " + e.toString());
e.printStackTrace();
throw e;
} }
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
}
'자바 > JAVA...Spring' 카테고리의 다른 글
Spring 3.2 & MyBatis] 수치형 바인드 처리 (command 클래스 작성) (0) | 2015.12.23 |
---|---|
[/AutoComplete.jsp] (0) | 2015.12.23 |
[/WEB-INF/src/log4j.xml] (0) | 2015.12.23 |
Spring 3.2 & MyBatis] 날짜형 바인드 (에러 메시지 정의) (0) | 2015.12.22 |
Spring 3.2 & MyBatis] 날짜형 바인드 (JSP 작성) (0) | 2015.12.22 |