본문 바로가기

자바모음/자바(java)

html 두개의 값 넘기기 input 두개의 값을 서버에 전송 방법

728x90
반응형
SMALL

 

 

input 박스로 두개의 값을 컨트롤러에 전달후 -> 문자열 결합하여 저장하고 싶을때

2가지방법

 

 

1.

html

<input multiple="multiple" id="fileInput" type="file" name="files" data-reqname="이미지"/>
<input type="hidden" name="fileDesc1" value="123456 일이삼사...">
<input type="text" name="userInputFileDesc1" value="789" >

여기서 input value="  789  " 이부분은 사용자가 직접 쓰도록 해줘도 상관 x

 

 

컨트롤러

String fileDesc = request.getParameter("fileDesc1");
String userInputFileDesc =  request.getParameter("userInputFileDesc1");


String combinedDesc1 = fileDesc + " " + userInputFileDesc;
System.out.println("combinedDesc1" + combinedDesc1); // 123456 일이삼사... 789
			
			
storageService.stores(test.aaa, String.valueOf(testVo.getTest()), combinedDesc1);

 

 

 

 

 

 

2. script 를 이용한 방법

 

html

<input type="hidden" id="fileDesc1" name="fileDesc1" value="123456 일이삼사...">

<input type="text" id="userInputDesc1">

 

 

 

script

function combineAndSubmit() {
    var hiddenValue = document.getElementById("fileDesc1").value;
    var userInputValue = document.getElementById("userInputDesc1").value;
    var combinedValue = hiddenValue + " " + userInputValue;
    // 이 부분에서 서버로 combinedValue 값을 전송하도록 처리할 수 있음
    // 예를 들어, form을 submit하거나 AJAX 요청을 보낼 수 있음
    console.log(combinedValue); // 확인을 위해 콘솔에 출력
}
728x90
반응형
LIST