티스토리 뷰

it

JSP EL

gams21 2023. 3. 12. 22:12
반응형


















EL : JSP 출력에 대한 부분을 쉽게 하기위해 개발한 TAG


기존의 값을<%= request.getParameter(“id”)%>로받았다면 (값을가져온게 없으면 null )


표현언어에서는 로받음 ${param.id} (값을 가져온게 없으면 공백 null을공백처리)






표현식과 표현언어로의 덧셈 구현


값을 입력받는 elForm.html


<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>





<form method=post action="result.jsp">

숫자 1 : <input type="text" name=num1>

숫자 2 : <input type="text" name=num2>

<input type=submit value="전송">

</form>

</body>

</html>






표현식과 표현언어로의 값을받는 result.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>

<head>

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

<title>Insert title here</title>

</head>

<body>

고전적인방식 :

<%

String str1= request.getParameter("num1");

String str2= request.getParameter("num2");



int num1= Integer.parseInt(str1);

int num2= Integer.parseInt(str2);

%>

<%=num1%>+<%=num2%>=<%=num1+num2%>


<!--[endif]-->

EL방식 :



${param.num1} + ${param.num2} = ${param.num1+param.num2}





</body>

</html>



------------

(서비스에서 MySQL 수동인 경우 직접 실행 시켜준후 cdm창에서 실행해줘야한다.)


MySQL설치 후 (http://dev.mysql.com/downloads/workbench/ ) -> cdm
mysqladmin u root create samplewdb
mysql u root (비번설정 안해줬으니 비번없이 로그인 됨)
use samplewdb (db사용)







(드라이버설치)
http://dev.mysql.com/downloads/ ->connector부분에서
ZIP파일 다운바당 압출풀면 musql-connector-java-5.1.22-bin (jar파일)
C- Promgram file java (jdk가 깔려있을 경우 jre가 깔려있을수도 있음) 어떤게 컴파일될지모르니 다집어넣어줘야함 ( JDK설치 디렉터리밑의 /jre/lib/ext )
jre만설치한경우는 jre설치 디렉터리밑의 lib/ext디렉터리에 복사


jsp MySQL 연결잘되는지 테스트


-드라이버 로드
try{
Class.formName(“com.mysql~~~
}
----
-드라이버 연결
...






반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/05   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함