WEB/JSP

if(session.getAttribute("userId") != null || session.getAttribute("userId") !="" ) 사용시 에러

ITGenerations 2018. 10. 5. 13:46

사용환경

jdk 1.9

eclipse oxygen

tomcat v8.5




JSP 공부를 하던차에 아래와 같이 사용하면 에러가 발생함을확인, 정확한 원인은 아직 파악못했으나

일단은, 아래와 같이 사용하면 에러가 발생함을 확인했다.

if(session.getAttribute("userId") != null || session.getAttribute("userId") !=""  )




공부중이던 소스

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

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>

</head>

<body>

<%-- || session.getAttribute("userId") !=""  --%>

<%

if(session.getAttribute("userId") != null ){

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

} else{

out.println("<script>alert('로그인 해라 시바')</script>");

}

%>


<form action="loginChk">

id:<input type="text" name="userId"><br>

pw:<input type="password" name="userPw"><br>

<input type="submit" name="login">

<input type="submit" name="signup">

</form>

</body>

</html>


해결책은 || 이후의 부분을 지우는 방법이 있는데, 그 외의 방법은 아직 파악하지 못했다.

이 글을 보고 위 해결책 외에 해답이 있다면 공유 해주시면 도움이 되겠습니다.