✅ HTML + 태그(JSP용)
✅ 태그 안에 자바 코드 삽입 (<% %>)
<% %>)<% %>
JSP ➔ 서블릿 변환시 JSP 엔진에 의해 처리
<%@ page 속성명="속성값" 속성명2="속성값2" %><%@ include file="포함할 페이지"%>
<% 자바코드문장; %>
<%
Date d = new Date();
int sum = 0;
for(int i = 1; i <= 10; i ++) {
sum += i;
}
Date d2 = null;
%>
현재 날짜 : <%= d %> </br>
1 ~ 10 합 : <%= sum%> </br>
d2 : <%= d2%>
✅ request.getParameter("name") : String 타입 리턴
⇨ 값이 없으면 비어있는 문자열 리턴
* redirect
ex) co.kr ➞ com
POST, PUT, DELETE 요청(고치는 행위)일 때 항상 redirect<body> <h1>로그인 정보 세션 저장</h1> <% String id = request.getParameter("userid"); if (id == null || id.equals("")) { response.sendRedirect("loginForm.jsp"); } else { String pw = request.getParameter("Password"); session.setAttribute("userid", id); session.setAttribute("Password", pw); out.print("안녕하세요 " + id + "\n"); out.print("<a href='loginInfo.jsp'> 정보보기 </a>"); } %> </body>
id == null || id.equals("")
- id를 입력 안하면 빈 문자열로 들어감 (localhost:8080/login.jsp?userid=&Password=1234)
<%=name%> / <%out.print(name);%><jsp:include page="삽입될페이지" flush="true"/>
: JSP 파일을 삽입
=
<%@ include file="포함할 페이지"%>
⇨ 최종 효과는 같으나 과정이 다름
- <%@ include~ > : 정적 / 변환 과정에서 두 파일이 합쳐짐 ➞ 컴파일/실행
- <jsp:inclue~ > : 동적 / 따로 변환, 실행 과정에서 해당 페이지로 이동 ➞ 실행 (≒ 메서드호출)