'전체 글'에 해당되는 글 227건

  1. 2008.09.25 Ajax post방식
  2. 2008.09.22 검색 추가,삭제 버튼 이벤트
  3. 2008.09.20 javascript encoding
posted by 준치 2008. 9. 25. 10:11

get방식은 써봤는데 post 방식이 안되서 과장님이 찾아주신 post 방식
보니까 소스상에서 다른점은 setRequestHeader()이게 다르더군...소스는 자바지만 함 써봅시다...ㅎㅎㅎ

// 포스트 방식
function callPostAjax() {
 var userId = document.getElementById("userId");
 var  v = userId.value;  // userID 값을 가지고 왔다.
 var url = "helloAjax.do";
 // 여러개의 파라미터 값을 넘기려면 and ~ and ~ 이런식으로 뒤에 붙여 보낸다.
 var param = "id=" + v;
 // Ajax 는 전송시 form 방식 으로 하지 않고 request에 담아서 보낸다.
 request.open("POST", url, true);
 request.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=UTF-8');
 request.setRequestHeader("Cache-Control","no-cache, must-revalidate");
 request.setRequestHeader("Pragma","no-cache");
 request.onreadystatechange = callback;
 request.send(param);                       

먼저 <input type="text" name="id" id="userId" onkeyup="callPostAjax();" />
바디부에서 onkeyup="callPostAjax();" 호출
GET 방식과 비교를 하여보면 get 방식에서는 url 에서 모든걸 가져갔지만
여기 POST 방식에서는 param 변수를 둬서 파라미터 값으로 가지고 가는 점이틀리다. 

그리고 EncodingFilter 에서 한글을 설정한다.
그 다음 HelloAjaxAction에서 설정

package hello;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class HelloAjaxAction extends Action {
 @Override
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
  String id = request.getParameter("id");  
  System.out.println(id);// 콘솔창 한글 찍히나 확인용  
  String msg = "Not Okay";
  if (id.equals("test")) {
   msg = "Okay";
  }

  return new ActionForward("/hello.jsp", false);

/* config.xml 에서 설정할 것을 여기서 할 수 있는데 다음은
    Ajax 가 이런 설정을 통하여 jsp 페이지를 통째로 가져다
    쓸 수 있다는 사실을 보여준다.
*/
 }
}

posted by 준치 2008. 9. 22. 15:00
검색 추가 버튼 클릭시 그냥 돌려서 보여주고 안보여주고...그냥..뭐...

//추가 함수
function addSearchArea()
{
 var disType; 
 for(var i = 1; i < 5; i++)
 {  
  disType = document.getElementById('SearchArea_' + i).style.display
  if(disType == "none")
  {
   document.getElementById('SearchArea_' + i).style.display = "block";
   break;
  }
 }
}

//줄이기 버튼
function SearchArea()
{
 var controlID = "ctl00_PlaceHolderMain_EzNetWebpart_";
 var disType;
 var disTxtType;
 for(var i = 4; i > 0; i--)
 {  
  disType = document.getElementById('SearchArea_' + i).style.display;
  
  if(disType == "block")
  {
   document.getElementById(controlID + 'SearchText_' + i).value = "";
   document.getElementById('SearchArea_' + i).style.display = "none";   
   break;
  }
 }
}
posted by 준치 2008. 9. 20. 16:55

현재 까지 써본것은 escape 와 unescape 함수인데 다른 값으로 변경되는 경우가 있어서
다른것은 테스트 해보려한다..ㅎㅎㅎ

* encodeURI() : decodeURI()
* encodeURIComponent() : decodeURIComponent()
* escape() : unescape()

테스트 결과 sharepoint SearchServer에서는 encodeURI 이 함수를 쓴다
밑에 소스 str에 원하는 한글을 넣으면 된다..ㅎㅎㅎ

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 </HEAD>
 <script language="javascript">
 function change(str)
 {
document.write("-----encodeURI </br>");
document.write(encodeURI(str));
document.write("</br>");
document.write("-----decodeURI </br>");
document.write(decodeURI(str));
document.write("</br>");
document.write("----encodeURIComponent </br>");
document.write(encodeURIComponent(str));
document.write("</br>");
document.write("----decodeURIComponent </br>");
document.write(decodeURIComponent(str));
document.write("</br>");
document.write("----escape </br>");
document.write(escape(str));
document.write("</br>");
document.write("----unescape </br>");
document.write(unescape(str));

}
 </script>
 <BODY>
  <input type="button" value="button" onclick="change('인사')">
 </BODY>
</HTML>