반응형

http://www.mkyong.com/java/how-to-convert-java-project-to-web-project-in-eclipse/


배워야 할께 만으요 ㅠㅠ

반응형
반응형

개발하고 있는게 완전 옜 JSP 


jsp 파일 안에.. 다 때려 박는 방식..

그래도 내가 아직 늙은이는 아닌데.. 하는 생각에 스프링을 도입했다..


근데 바껴야 할 소스가 너무도 많아서 .. 꽁수를 생각했다..


jsp 페이지는 예전 그대로 두고 

ajax  에서 컨트롤러 호출해서 

데이타만 가져와서 예전 jsp에 뿌려보자..


어느정도 가닥이 잡혀서 적어둔다..





클라이언트

//제이쿼리 넣기

//$.ajax 요렇게 하믄 ajax 통신 모듈 제공

<script src="http://code.jquery.com/jquery-1.9.1.js"></script> 


 $('#tempSave').click(function() {  // 어떤(ID) 부분 클릭하면 

  var formdata = new FormData(document.getElementById('tempSaveform'));

   // 폼 정보 읽어오기


    $.ajax({

// 컨트롤러 호출  

       url: '/tempSave.do',  

       data: formdata,

       dataType: 'text',

       type: 'POST',

       success: function(response){

// json 형태로 받아옴

        var data = jQuery.parseJSON(response);

//여기서 수신된 데이타를 세팅해서 뿌려주면 됨 아래 참고 예

//$('#result').html( data.JsonLogo.image ); // 묶여서 올경우 저런식으로 데이타만 가져옴

          console.log(data );

       },error: function (jqXHR) {

        console.log(jqXHR);

        }

     });

    return false;

 });





서버

    @RequestMapping(value="/tempSave.do", method = RequestMethod.POST)  //url 과 메소드 방식 체크 

    @ResponseBody

    public  String tempSave(@ModelAttribute BoardVo boardVo) throws Exception{

      try{

     boardVo.setReturn_message("통신 성공.");

      }catch (Exception e){

 boardVo.setReturn_message("통신 실패");

   log.debug(e);

      }

return boardVo.getReturn_message();

    }


심플하다 심플해~


아참  JSON 사용을 위해 아래처럼 servlet_context 를  설정해 주어야 한다 

라이브러리도 받으시구요 ~


<mvc:annotation-driven >

<mvc:message-converters register-defaults="true">

<bean class = "org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">

<property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" />

</bean>

</mvc:message-converters>

</mvc:annotation-driven>  


메이븐 pom.xml (라이브러리)

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-annotations</artifactId>

<version>2.2.2</version>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-core</artifactId>

<version>2.2.2</version>

<scope>compile</scope>

</dependency>

<dependency>

<groupId>com.fasterxml.jackson.core</groupId>

<artifactId>jackson-databind</artifactId>

<version>2.2.2</version>

<scope>compile</scope>

</dependency>


바빠서 두서 없이 남겨요  ㅎㅎ





반응형
반응형


localIp.jsp

테스트 하다 보면 로컬 아이피는 그냥 데이타를 박아두고 쓰고 싶을때가 있다..


그래서 찾아봤다.


<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html lang="ko">

<BODY>


<%! String userIP = null;%>

<%-- Test if ip begins with 192.168 (DCU) or 127.0.0.1 (localhost)  --%>

<%userIP = request.getRemoteAddr();   

// 생성된 아이피 String 변수 삽입 첫글자부터 7번째까지 비교  

if ((userIP.equals("127.0.0.1")))  {    %>

<H1>ACCESS GRANTED</H1>

<% } else {     

    out.println("<H1>ACCESS DENIED</H1>");

    out.println("Illegal access from an external machine with IP Address: " + userIP);

}

%>

</BODY>

</HTML>


혹 

0:0:0:0:0:0:0:1  로 나온다면 윈도우 7부터 ipv6 가 적용되어서 그러타 한다 변경 하고 싶으면 ~~


아래 url 참조 하세용~


http://kdarkdev.tistory.com/3 


특정os에서 발생하는 문제이고(windows7) 톰캣을 사용했을때 해결 방법이다

request.getRemoteAddr()로 ip를 가져올때 0:0:0:0:0:0:0:1라고 나온다면 
이것은 인터넷 주소체계 ipv4, ipv6의 루프백 주소 차이이므로 비정상은 아니다
ipv4의 루프백 주소는 127.0.0.1
ipv6의 루프백 주소는 0:0:0:0:0:0:0:1
위와 같고 windows7은 기본적으로 ipv6 type으로 ip를 리턴하므로 ipv4형식으로 ip를 보고 싶다면 was 기동시 vm argument를 ipv4 type으로 주면 된다
방법은 크게 2가지

*** 루프백 주소란? ***
네트워크상에서 자기자신을 나타내는 인터페이스, 주소  ...






반응형
반응형
친구와 동시개발중 플젝이 있다.. 
github 사용하다 보니 디비정보가 그대로 git에 올라가서.. 비공개를 찾았보았다

bitbucket.org 찾았다.

현재 소스가 커밋되면 자동 빌드 가능하게 설정해 두었다..

비공개 git이라 설정에 애를 먹었는데 아래방법으로 불러오니 프로젝트가 인식하였다

https://<user>:<pass>@bitbucket.org/<user>/<project>.git

이렇게 해주면  프로젝트 인식하드랑 ~~ ㅎㅎ



ㅋㅋㅋ

만날 해딩하는구나 ~~



반응형
반응형



디비 필드에 업로드 된 파일명을 | 구분자로 넣었다


1_파일.xls|2_파일.xls|3_파일.xls|


split 으로 배열화 

String  attach_files_Array[] = new String[3];  //4개 까지만 ~쓸꺼임


attach_files_Array = attach_files.split("[|]");


요로케롬 하면 

ex) 차곡차곡 잘린다 

1_파일.xls

2_파일.xls

3_파일.xls


루프로 돌리면서 비교


<%for(int i =0; i < attach_files_Array.length; i++){ %>

     <%if (attach_files_Array[i].matches("^1.*")){  // 정규식 ^ 첫번째값 검색%>

        <li>1번째파일 있음</li>

     <%}else if(attach_files_Array[i].matches("^2.*")){ %>

           <li>2번째파일 있음</li>

<%}else{ %>                <li>파일없음</li>

 <%}%>

<%}%>



만족스릅다 ~ 




개발좀 술술 풀리게 해주세요~

반응형
반응형

test.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html lang="ko">

<head>

<meta charset="utf-8">

</head>

<body>


<%!public static boolean isNaN(String str) {

    boolean check = true;

    for (int i = 0; i < str.length(); i++) {

        if (!Character.isDigit(str.charAt(i))) {

            check = false;

            break;

        } // end if

    } //end for

    return check;

} //isNaN%>


<% 

String idx ="";

idx =request.getParameter("idx");


if(  idx == null || idx.equals("")  || idx .equals("null") || !isNaN(idx)){

out.println("<script> alert('잘못된 접근입니다.'); history.back();</script>");      

}


%>

</body>

</html>


넘어온 값이 없거나 

숫자 타입이 아니라면 잘못된 접근

반응형
반응형

위에 체크박스 선택시 

아래쪽 input text  disabled 시킨다


다중 체크 박스 적용




<script type="text/javascript">

jQuery( document ).ready( function(){

$("input[name=bond_type]").click(function(){ // 채권 종류 클릭 하면

$(".organize").attr("disabled",true);

/* 하나씩 선택 할때

$('input:checkbox[name="bond_type"]').each(function(){  //  해당 이름 체크 박스 모두 

console.log( $(this).val() );

if($('input:checkbox[name="bond_type"]:checked').val() == 1){ // 체크 값에 따라  

$(".organize").eq(0).attr("disabled",false);

$(".organize").eq(1).attr("disabled",false);

}else if($('input:checkbox[name="bond_type"]:checked').val()  == 2){

$(".organize").eq(2).attr("disabled",false);

$(".organize").eq(3).attr("disabled",false);

}else if($('input:checkbox[name="bond_type"]:checked').val()  == 3){

$(".organize").eq(4).attr("disabled",false);

$(".organize").eq(5).attr("disabled",false);

}else if($('input:checkbox[name="bond_type"]:checked').val()  == 4){

$(".organize").eq(6).attr("disabled",false);

$(".organize").eq(7).attr("disabled",false);

}else if($('input:checkbox[name="bond_type"]:checked').val()  == 5){

$(".organize").eq(8).attr("disabled",false);

$(".organize").eq(9).attr("disabled",false);

}else if($('input:checkbox[name="bond_type"]:checked').val()  == 6){

$(".organize").eq(10).attr("disabled",false);

$(".organize").eq(11).attr("disabled",false);

}else{ // 체크 된게 없으면 모두 disabled

$(".organize").attr("disabled",true);

}

});

});

*/

/*다중 체크 */

$('input:checkbox[name="bond_type"]:checked').each(function(){  //  체크된 박스만 비교 

console.log( $(this).val() );

if($(this).val()  == 1){ // 체크 값에 따라  

$(".organize").eq(0).attr("disabled",false);

$(".organize").eq(1).attr("disabled",false);

if($(this).val()   == 2){

$(".organize").eq(2).attr("disabled",false);

$(".organize").eq(3).attr("disabled",false);

if($(this).val()   == 3){

$(".organize").eq(4).attr("disabled",false);

$(".organize").eq(5).attr("disabled",false);

if($(this).val()   == 4){

$(".organize").eq(6).attr("disabled",false);

$(".organize").eq(7).attr("disabled",false);

if($(this).val()   == 5){

$(".organize").eq(8).attr("disabled",false);

$(".organize").eq(9).attr("disabled",false);

if($(this).val()   == 6){

$(".organize").eq(10).attr("disabled",false);

$(".organize").eq(11).attr("disabled",false);

if($(this).val()  == 0){ // 체크 된게 없으면 모두 disabled

$(".organize").attr("disabled",true);

}

});

});

</script>

<div>

<h4 class="tit-border">1. 종류를 선택하세요.</h4>

<ul class="wrap-pd">

<li style="width:160px"><input type="checkbox"  name="bond_type" value="1"  > 1</li>

<li style="width:160px"><input type="checkbox"  name="bond_type" value="2"  > 2</li>

<li style="width:160px"><input type="checkbox"  name="bond_type" value="3"  > 3</li>

<li style="width:160px"><input type="checkbox"  name="bond_type" value="4"  > 4</li>

<li style="width:160px"><input type="checkbox"  name="bond_type" value="5"  > 5</li>

<li><input type="checkbox"  name="bond_type" value="6"   >기타</li>

</ul>

</div>

<div>

<h4 class="tit-border">2. 입력.</h4>

<div class="ovr-hdn">

<div class="f-r">

<table cellspacing="0" cellpadding="0" class="tbl-line">

<caption class="tit-caption">&nbsp;</caption>

<colgroup>

<col width="127">

<col width="177">

<col width="182">

</colgroup>

<thead>

<tr class="hr">

<th scope="col">종류</th>

<th scope="col" class="txt-c">건수</th>

<th scope="col" class="txt-c">money</th>

</tr>

</thead>

<tbody id="tbody_test">

<tr>

<th scope="row">1</th>

<td class="txt-r"><input type="text"  name="organize_quantity_1" value="0"   class="organize" style="width:90px;"> 건</td>

<td class="txt-r"><input type="text"   name="organize_amount_1" value="0"  class="organize" style="width:110px;"> 원</td>

</tr>

<tr>

<th scope="row">2</th>

<td class="txt-r"><input type="text" name="organize_quantity_2" value="0"  class="organize" style="width:90px;"> 건</td>

<td class="txt-r"><input type="text"  name="organize_amount_2" value="0"  class="organize" style="width:110px;"> 원</td>

</tr>

<tr>

<th scope="row">3</th>

<td class="txt-r"><input type="text" name="organize_quantity_3" value="0" class="organize" style="width:90px;"> 건</td>

<td class="txt-r"><input type="text"  name="organize_amount_3" value="0" class="organize" style="width:110px;"> 원</td>

</tr>

<tr>

<th scope="row">4</th>

<td class="txt-r"><input type="text" name="organize_quantity_4" value="0" class="organize" style="width:90px;"> 건</td>

<td class="txt-r"><input type="text"  name="organize_amount_4" value="0" class="organize" style="width:110px;"> 원</td>

</tr>

<tr>

<th scope="row">5</th>

<td class="txt-r"><input type="text" name="organize_quantity_5" value="0" class="organize" style="width:90px;"> 건</td>

<td class="txt-r"><input type="text"  name="organize_amount_5" value="0" class="organize" style="width:110px;"> 원</td>

</tr>

<tr class="hr">

<td>기타</td>

<td class="txt-r"><input type="text" name="organize_quantity_6" value="0"  class="organize" style="width:90px;"> 건</td>

<td class="txt-r"><input type="text"  name="organize_amount_6" value="0"  class="organize" style="width:110px;"> 원</td>

</tr>

</tbody>

<tfoot>

<tr class="last-border">

<td>합계</td>

<td class="txt-r"><input type="text"  id="organize_quantity_sum" name="organize_quantity_sum" value="0"  class="input-text txt-r" style="width:90px;"  readonly> 건</td>

<td class="txt-r"><input type="text"  id="organize_amount_sum" name="organize_amount_sum" value="0"  class="input-text txt-r" style="width:110px;" readonly> 원</td>

</tr>

</tfoot>

</table>

</div>

</div>

</div>


checkbox-disabled.jsp


반응형
반응형

<bean id="boardService" class="board.service.BoardServiceImpl">

<!--  property name 은 set name과 맵핑 -->

<property name="boarddao1" ref="boarddao2"/>

</bean>



http://jwlee1728.egloos.com/1805102

반응형
반응형

login.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html lang="ko">

<head>

<meta charset="utf-8">

<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-darkness/jquery-ui.css" type="text/css" media="all" />


<script src="/js/jquery-1.8.3.min.js"></script>

<script src="/js/jquery.form.min.js"></script>


<script type="text/javascript">


$(document).ready(function() {

$("#layer_ajax").hide();

$("#layer_ajax").ajaxStart(function(){

$("#wait").css("display","block");

});

  $("#layer_ajax").ajaxComplete(function(){

$("#wait").css("display","none");

});

$("#layer_ajax").ajaxError(function(){

alert("통신 애러");

});


$(".btn-login").click(function(e){

//아래 코드 실행

dataString = $("#login").serialize();

//form 과 직렬화..

$.ajaxSetup({

url:"/login/login_proc.jsp",  

data : dataString,  // 넘겨질 데이타 

       type: "POST",

success:function(result) {

var arr_data = result.split("*");

var data1= arr_data[0];

var data2= arr_data[1];

if(trim(data1) == null || trim(data1) =="" ){

// 받아온 결과가 없으면 아무 작업 안함

}else{

location.href=data1;

}

// 받아온 메세지 전달 (실패 메세지..)

$("#layer_ajax").html(data2);

// 실패면 패스워드 데이타 지우고 포커스 이동

$("input[name=password]").val('');

$("input[name=password]").focus(); 

}  

});  

 

$.ajax();

$("#layer_ajax").show();

}); 


});

// 공백 제거

function trim(txt)

{

return txt.replace(/(^\s*)|(\s*$)/g, "");

}

</script>


</head>

<body>


<form  id ="login" >

<!-- 로그인 전에 url 을 전달하기 위해 히든으로 url 받아둔다 -->

<input type="hidden"  name="redirectURI"  value="<%=(request.getAttribute("redirectURI"))==null?"/":request.getAttribute("redirectURI")%>" >

<fieldset class="login-form">

<p class="chk-p"><input type="radio" class="screen-out">

<label for="" class="label-point"><span class="ir radio-box active"></span>개인회원</label><input type="radio" class="screen-out">

<label for="" class="label-point"><span class="ir radio-box active"></span>법인회원</label></p>

<p class="input"><input type="text"  name="user" class="input-text"></p>

<p class="input"><input type="password" name="password"  class="input-text"></p>

<button type="button" class="btn-login">로그인</button>

<div id="layer_ajax"></div>

<p class="chk-p"><input type="checkbox" class="screen-out"><label for="" class="label-point"><span class="ir check-box active"></span>아이디 저장</label></p>

</fieldset>

</form>

</body>

</html>


login_proc.jsp


<%@ page contentType="text/html;charset=EUC-KR"%>

<%

    // 로그인 정보 설정

    String userID="";

    String userPWD="";

    String userLevel="";

    String loginMsg = "";

    String redirectURI ="";

    String level ="";

    

    // login.jsp로부터 form data를 받는다

    String id = request.getParameter("user");

    String pwd = request.getParameter("password");

    

    String member_select_query="select userid,level,userpw from Member where userid=\'"+id+"\'and userpw = \'"+pwd+"\';";

 try {

  ResultSet member_info = stmt.executeQuery(member_select_query);

  while(member_info.next())

  {

  userID=member_info.getString("userid");

  userLevel=member_info.getString("level");

  userPWD = member_info.getString("userpw");

  }

 }

 catch(Exception e)

 {

  out.println("[ERROR] "+e.getMessage());

 }

    

    // id, pwd가 맞을 경우 실행

    if(userID.equals(id) && userPWD.equals(pwd)) 

    {

        session.setAttribute("s_Level",userLevel);

        session.setAttribute("s_Id", userID);

        loginMsg ="성공";

        //response.sendRedirect("./main.jsp"); // main.jsp 에 session 정보를 보낸다

        redirectURI  = request.getParameter("redirectURI");

    }

    else

    {

        loginMsg ="로그인 실패";

       // response.sendRedirect("./main.jsp");

    }

%>

<!-- * 로 구분하여 다중 메세지 전송 -->

<%=redirectURI%>*<%=loginMsg%>


login_check.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>


<%

    String checkLevel = "";

    String checkId = "";

    

    checkLevel = (String)session.getAttribute("s_Level");

   

    if(checkLevel == null) // 세션이 없으면 로그인 페이지 이동

    {

        String login_url = "/pages/login/login.jsp";  //로그인페이지

        request.setAttribute("redirectURI", request.getRequestURI());

        RequestDispatcher dispatcher = request.getRequestDispatcher( login_url );

        dispatcher.forward(request, response); 

    }

    checkId = (String)session.getAttribute("s_Id");

%>



로그인이 필요한곳에 파일 인쿠르드


<%@include file="/login/login_check.jsp" %>


반응형
반응형

위의 예제 응용입니다 
<option value='t001' <%=topographyValue.equals("t001") ? "selected" : "" %> >어쩌구</option> 
혹은 
------------------------------------------------------- 
function setComboValue(obj, str){ 
var otype; //OBJECT TYPE 
if (obj == null) return ; 
if (chk_Blank(str)) return ; 
otype = (obj.type).substring(0,6); 

if (otype != "select") return ; 

for (var index = 0; index < obj.length; index++) { 
if (obj.options[index].value != '') { 
if (trim(obj.options[index].value) == trim(str)) { 
obj.options[index].selected = true; 

} else { 
if (trim(obj.options[index].text) == trim(str)) { 
obj.options[index].selected = true; 





공통 자바스크립트 펑션에 요너마 만들어 놓고 

<body onload="init()"> //body에 init() javascript호출후 

자바스크립트 정의하는곳에 요너마 낑겨 넣으삼 

function init(){ 
f = document.writeForm; //writeForm은 select박스를 둘러싼 form name 
setComboValue(f.topography, "<%=topographyValue%>"); 
}


okjsp 펌


실제 적용 부분...


<form id="form" name="form" method="post" enctype="multipart/form-data">


$(document).ready(function() {

init();

});

function init(){ 

setComboValue(form.bond_type, "<%=bond_type%>");

setComboValue(form.term, "<%=bond_term%>");

//셀렉트 박스 disabled

document.all['bond_type'].disabled = true;

document.all['term'].disabled = true;

}

function setComboValue(obj, str){ 

var otype; //OBJECT TYPE 

if (obj == null) return ; 

//if (chk_Blank(str)) return ; 

otype = (obj.type).substring(0,6); 

if (otype != "select") return ; 


for (var index = 0; index < obj.length; index++) { 

if (obj.options[index].value != '') { 

if (obj.options[index].value == str) { 

obj.options[index].selected = true;


} else { 

if (obj.options[index].text == str) { 

obj.options[index].selected = true; 

}



반응형

+ Recent posts