본문 바로가기
MEMO/Java-memo

post 통신에 따른 조건문 핸들링 - input type hidden,text

by eungSe__ 2024. 6. 25.

  null일 경우 - 연산기호 , 값이 있는 경우 - equals

equals("hong") 또는 == "hong" 으로 체크한다면 새로고침하고 들어갈 시 초기값이 null이어서 아예 인식불가 - 에러가 떠버림


==> 이럴땐 그냥 값을 핸들링하지 말고 null로 좌지우지 해주자!

      ( 연산기호 == 로값이 있는지 없는지만 체크 ) ^_________^

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	String data = (String)request.getParameter("mid");
	out.print(data+"<br>");
	//새로고침->인식불가(500)
	if(data==null){ //버튼을 누르기 전
		out.print("11");
	}else{ //버튼을 눌렀을 때
		out.print("22");
	}

%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>post 통신에 따른 조건문 핸들링</title>
</head>
<body>
	<form action="./jsp9.jsp" method="post" id="frm">
		<input type="hidden" name="mid" value="">
		<input type="button" value="클릭" onclick="gopage()">
	</form>
</body>

<script type="text/javascript">
	function gopage(){
		frm.mid.value="hong";
		frm.submit();	
	}
		
</script>

</html>

 

🔽

'MEMO > Java-memo' 카테고리의 다른 글

문자열로 변환하는 형태 : String.valueOf,toString(),(String)  (0) 2024.06.19
금액에 , 찍기  (0) 2024.05.31
IO,Network 정리  (0) 2024.05.24
interface 정리  (0) 2024.05.24
abstract 정리  (0) 2024.05.24