--- WebTest/.classpath
+++ WebTest/.classpath
... | ... | @@ -1,13 +1,33 @@ |
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?> |
2 | 2 |
<classpath> |
3 |
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> |
|
4 |
- <classpathentry kind="src" path="src/main/java"/> |
|
3 |
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> |
|
4 |
+ <attributes> |
|
5 |
+ <attribute name="maven.pomderived" value="true"/> |
|
6 |
+ </attributes> |
|
7 |
+ </classpathentry> |
|
8 |
+ <classpathentry kind="src" output="target/classes" path="src/main/java"> |
|
9 |
+ <attributes> |
|
10 |
+ <attribute name="optional" value="true"/> |
|
11 |
+ <attribute name="maven.pomderived" value="true"/> |
|
12 |
+ </attributes> |
|
13 |
+ </classpathentry> |
|
5 | 14 |
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0"> |
6 | 15 |
<attributes> |
7 | 16 |
<attribute name="owner.project.facets" value="jst.web"/> |
8 | 17 |
</attributes> |
9 | 18 |
</classpathentry> |
10 |
- <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> |
|
11 |
- <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> |
|
12 |
- <classpathentry kind="output" path="build/classes"/> |
|
19 |
+ <classpathentry kind="src" output="target/test-classes" path="src/test/java"> |
|
20 |
+ <attributes> |
|
21 |
+ <attribute name="optional" value="true"/> |
|
22 |
+ <attribute name="maven.pomderived" value="true"/> |
|
23 |
+ <attribute name="test" value="true"/> |
|
24 |
+ </attributes> |
|
25 |
+ </classpathentry> |
|
26 |
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> |
|
27 |
+ <attributes> |
|
28 |
+ <attribute name="maven.pomderived" value="true"/> |
|
29 |
+ <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> |
|
30 |
+ </attributes> |
|
31 |
+ </classpathentry> |
|
32 |
+ <classpathentry kind="output" path="target/classes"/> |
|
13 | 33 |
</classpath> |
--- WebTest/.gitignore
+++ WebTest/.gitignore
... | ... | @@ -1,1 +1,2 @@ |
1 | 1 |
/build/ |
2 |
+/target/ |
--- WebTest/.project
+++ WebTest/.project
... | ... | @@ -20,8 +20,14 @@ |
20 | 20 |
<arguments> |
21 | 21 |
</arguments> |
22 | 22 |
</buildCommand> |
23 |
+ <buildCommand> |
|
24 |
+ <name>org.eclipse.m2e.core.maven2Builder</name> |
|
25 |
+ <arguments> |
|
26 |
+ </arguments> |
|
27 |
+ </buildCommand> |
|
23 | 28 |
</buildSpec> |
24 | 29 |
<natures> |
30 |
+ <nature>org.eclipse.m2e.core.maven2Nature</nature> |
|
25 | 31 |
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature> |
26 | 32 |
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> |
27 | 33 |
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> |
--- WebTest/.settings/org.eclipse.jdt.core.prefs
+++ WebTest/.settings/org.eclipse.jdt.core.prefs
... | ... | @@ -3,5 +3,9 @@ |
3 | 3 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 |
4 | 4 |
org.eclipse.jdt.core.compiler.compliance=1.8 |
5 | 5 |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
6 |
+org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled |
|
6 | 7 |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
8 |
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning |
|
9 |
+org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore |
|
10 |
+org.eclipse.jdt.core.compiler.release=disabled |
|
7 | 11 |
org.eclipse.jdt.core.compiler.source=1.8 |
+++ WebTest/.settings/org.eclipse.m2e.core.prefs
... | ... | @@ -0,0 +1,4 @@ |
1 | +activeProfiles= | |
2 | +eclipse.preferences.version=1 | |
3 | +resolveWorkspaceProjects=true | |
4 | +version=1 |
--- WebTest/.settings/org.eclipse.wst.common.component
+++ WebTest/.settings/org.eclipse.wst.common.component
... | ... | @@ -1,14 +1,22 @@ |
1 | 1 |
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> |
2 |
- |
|
3 |
- <wb-module deploy-name="WebTest"> |
|
4 |
- |
|
5 |
- <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> |
|
6 |
- |
|
7 |
- <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> |
|
8 |
- |
|
9 |
- <property name="java-output-path" value="/WebTest/build/classes"/> |
|
10 |
- <property name="context-root" value="WebTest"/> |
|
11 | 2 |
|
12 |
- </wb-module> |
|
13 | 3 |
|
4 |
+ <wb-module deploy-name="WebTest-0.0.1-SNAPSHOT"> |
|
5 |
+ <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> |
|
6 |
+ |
|
7 |
+ |
|
8 |
+ <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> |
|
9 |
+ |
|
10 |
+ |
|
11 |
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> |
|
12 |
+ |
|
13 |
+ |
|
14 |
+ <property name="java-output-path" value="/WebTest/build/classes"/> |
|
15 |
+ |
|
16 |
+ <property name="context-root" value="WebTest"/> |
|
17 |
+ |
|
18 |
+ |
|
19 |
+ </wb-module> |
|
20 |
+ |
|
21 |
+ |
|
14 | 22 |
</project-modules> |
+++ WebTest/.settings/org.eclipse.wst.validation.prefs
... | ... | @@ -0,0 +1,2 @@ |
1 | +disabled=06target | |
2 | +eclipse.preferences.version=1 |
+++ WebTest/pom.xml
... | ... | @@ -0,0 +1,48 @@ |
1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
2 | + <modelVersion>4.0.0</modelVersion> | |
3 | + <groupId>WebTest</groupId> | |
4 | + <artifactId>WebTest</artifactId> | |
5 | + <version>0.0.1-SNAPSHOT</version> | |
6 | + <packaging>war</packaging> | |
7 | + <dependencies> | |
8 | + <dependency> | |
9 | + <groupId>mysql</groupId> | |
10 | + <artifactId>mysql-connector-java</artifactId> | |
11 | + <version>5.1.49</version> | |
12 | + </dependency> | |
13 | + <dependency> | |
14 | + <groupId>org.junit.jupiter</groupId> | |
15 | + <artifactId>junit-jupiter-api</artifactId> | |
16 | + <version>5.7.2</version> | |
17 | + <scope>test</scope> | |
18 | + </dependency> | |
19 | + <dependency> | |
20 | + <groupId>javax.servlet</groupId> | |
21 | + <artifactId>jstl</artifactId> | |
22 | + <version>1.2</version> | |
23 | + </dependency> | |
24 | + <dependency> | |
25 | + <groupId>org.apache.taglibs</groupId> | |
26 | + <artifactId>taglibs-standard-impl</artifactId> | |
27 | + <version>1.2.5</version> | |
28 | + <scope>runtime</scope> | |
29 | + </dependency> | |
30 | + | |
31 | + </dependencies> | |
32 | + <build> | |
33 | + <plugins> | |
34 | + <plugin> | |
35 | + <artifactId>maven-compiler-plugin</artifactId> | |
36 | + <version>3.8.1</version> | |
37 | + <configuration> | |
38 | + <source>1.8</source> | |
39 | + <target>1.8</target> | |
40 | + </configuration> | |
41 | + </plugin> | |
42 | + <plugin> | |
43 | + <artifactId>maven-war-plugin</artifactId> | |
44 | + <version>3.2.3</version> | |
45 | + </plugin> | |
46 | + </plugins> | |
47 | + </build> | |
48 | +</project>(No newline at end of file) |
+++ WebTest/src/main/java/config/Database.java
... | ... | @@ -0,0 +1,28 @@ |
1 | +package config; | |
2 | + | |
3 | +import java.sql.Connection; | |
4 | +import java.sql.DriverManager; | |
5 | + | |
6 | +public class Database { | |
7 | + | |
8 | + private static String dbHost = "db.asin21.com"; | |
9 | + private static String dbUser = "demo07"; | |
10 | + private static String dbPass = "demo07!"; | |
11 | + private static String dbName = "db_demo07"; | |
12 | + | |
13 | + private static String dbDriver = "com.mysql.jdbc.Driver"; | |
14 | + private static String dbUrl = "jdbc:mysql://" + dbHost + "/" + dbName; | |
15 | + | |
16 | + public static Connection getConnection() { | |
17 | + | |
18 | + try { | |
19 | + Class.forName(dbDriver); | |
20 | + return DriverManager.getConnection(dbUrl, dbUser, dbPass); | |
21 | + | |
22 | + } catch (Exception e) { | |
23 | + e.printStackTrace(); | |
24 | + return null; | |
25 | + | |
26 | + } | |
27 | + } | |
28 | +} |
+++ WebTest/src/main/java/config/EncodingFiter.java
... | ... | @@ -0,0 +1,74 @@ |
1 | +package config; | |
2 | + | |
3 | +import java.io.IOException; | |
4 | +import java.sql.Connection; | |
5 | + | |
6 | +import javax.servlet.Filter; | |
7 | +import javax.servlet.FilterChain; | |
8 | +import javax.servlet.FilterConfig; | |
9 | +import javax.servlet.ServletException; | |
10 | +import javax.servlet.ServletRequest; | |
11 | +import javax.servlet.ServletResponse; | |
12 | +import javax.servlet.annotation.WebFilter; | |
13 | + | |
14 | +/** | |
15 | + * Servlet Filter implementation class EncordingFiter | |
16 | + */ | |
17 | +@WebFilter("/*") | |
18 | +public class EncodingFiter implements Filter { | |
19 | + | |
20 | + final private String charset = "utf-8"; | |
21 | + | |
22 | + /** | |
23 | + * Default constructor. | |
24 | + */ | |
25 | + public EncodingFiter() { | |
26 | + | |
27 | + System.out.println("Fiter Created!"); | |
28 | + | |
29 | + } | |
30 | + | |
31 | + /** | |
32 | + * @see Filter#destroy() | |
33 | + */ | |
34 | + public void destroy() { | |
35 | + | |
36 | + System.out.println("System Down!"); | |
37 | + | |
38 | + } | |
39 | + | |
40 | + /** | |
41 | + * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) | |
42 | + */ | |
43 | + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { | |
44 | + | |
45 | + System.out.println("서블릿 요청이 있을 때마다 실행"); | |
46 | + | |
47 | + request.setCharacterEncoding(charset); | |
48 | + response.setContentType("text/html; charset=utf-8"); | |
49 | + response.setCharacterEncoding(charset); | |
50 | + | |
51 | + chain.doFilter(request, response); | |
52 | + } | |
53 | + | |
54 | + /** | |
55 | + * @see Filter#init(FilterConfig) | |
56 | + */ | |
57 | + public void init(FilterConfig fConfig) throws ServletException { | |
58 | + | |
59 | + System.out.println("system Start"); | |
60 | + Connection conn = Database.getConnection(); | |
61 | + if(conn != null){ | |
62 | + System.out.println(conn + " : DB Connention Success!"); | |
63 | + }else { | |
64 | + System.out.println("DB Connention Fail!!"); | |
65 | + } | |
66 | + } | |
67 | +} | |
68 | + | |
69 | + | |
70 | + | |
71 | + | |
72 | + | |
73 | + | |
74 | + |
+++ WebTest/src/main/java/control/MemberServlet.java
... | ... | @@ -0,0 +1,73 @@ |
1 | +package control; | |
2 | + | |
3 | +import java.io.IOException; | |
4 | +import java.util.HashMap; | |
5 | +import java.util.List; | |
6 | +import java.util.Map; | |
7 | + | |
8 | +import javax.servlet.RequestDispatcher; | |
9 | +import javax.servlet.ServletException; | |
10 | +import javax.servlet.annotation.WebServlet; | |
11 | +import javax.servlet.http.HttpServlet; | |
12 | +import javax.servlet.http.HttpServletRequest; | |
13 | +import javax.servlet.http.HttpServletResponse; | |
14 | + | |
15 | +import model.MemberDAO; | |
16 | +import model.MemberDTO; | |
17 | + | |
18 | +/** | |
19 | + * Servlet implementation class MemberServlet | |
20 | + */ | |
21 | +@WebServlet("/Member/*") | |
22 | +public class MemberServlet extends HttpServlet { | |
23 | + private static final long serialVersionUID = 1L; | |
24 | + | |
25 | + /** | |
26 | + * @see HttpServlet#HttpServlet() | |
27 | + */ | |
28 | + public MemberServlet() { | |
29 | + super(); | |
30 | + // TODO Auto-generated constructor stub | |
31 | + } | |
32 | + | |
33 | + /** | |
34 | + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) | |
35 | + */ | |
36 | + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
37 | + | |
38 | + String url = request.getRequestURL().toString(); | |
39 | + String viewPage = null; | |
40 | + | |
41 | + MemberDAO dao = new MemberDAO(); | |
42 | + | |
43 | + if(url.indexOf("list.do") != -1) { | |
44 | + List<MemberDTO> list = dao.MemberList(); | |
45 | + Map<String, Object> map = new HashMap<String, Object>(); | |
46 | + | |
47 | + map.put("list", list); | |
48 | + map.put("count", list.size()); | |
49 | + System.out.println(map); | |
50 | + request.setAttribute("map", map); | |
51 | + | |
52 | + viewPage = "/view/list.jsp"; | |
53 | + RequestDispatcher goUrl = request.getRequestDispatcher(viewPage); | |
54 | + goUrl.forward(request, response); | |
55 | + }else { | |
56 | + | |
57 | + } | |
58 | + | |
59 | + } | |
60 | + | |
61 | + /** | |
62 | + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) | |
63 | + */ | |
64 | + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | |
65 | + // TODO Auto-generated method stub | |
66 | + doGet(request, response); | |
67 | + } | |
68 | + | |
69 | +} | |
70 | + | |
71 | + | |
72 | + | |
73 | + |
+++ WebTest/src/main/java/model/MemberDAO.java
... | ... | @@ -0,0 +1,70 @@ |
1 | +package model; | |
2 | + | |
3 | +import java.sql.Connection; | |
4 | +import java.sql.PreparedStatement; | |
5 | +import java.sql.ResultSet; | |
6 | +import java.util.ArrayList; | |
7 | +import java.util.List; | |
8 | + | |
9 | +import config.Database; | |
10 | + | |
11 | +public class MemberDAO { | |
12 | + | |
13 | + public List<MemberDTO> MemberList(){ | |
14 | + | |
15 | + List<MemberDTO> list = new ArrayList<MemberDTO>(); | |
16 | + | |
17 | + Connection conn = null; | |
18 | + PreparedStatement pstmt = null; | |
19 | + ResultSet rs = null; | |
20 | + | |
21 | + String query = "select * from user"; | |
22 | + | |
23 | + try { | |
24 | + conn = Database.getConnection(); | |
25 | + pstmt = conn.prepareStatement(query); | |
26 | + rs = pstmt.executeQuery(); | |
27 | + | |
28 | + while(rs.next()) { | |
29 | + int no = rs.getInt("no"); | |
30 | + String name = rs.getString("name"); | |
31 | + int age = rs.getInt("age"); | |
32 | + String role = rs.getString("role"); | |
33 | + | |
34 | + MemberDTO dto = new MemberDTO(); | |
35 | + | |
36 | + dto.setNo(no); | |
37 | + dto.setName(name); | |
38 | + dto.setAge(age); | |
39 | + dto.setRole(role); | |
40 | + | |
41 | + list.add(dto); | |
42 | + } | |
43 | + return list; | |
44 | + | |
45 | + } catch (Exception e) { | |
46 | + e.printStackTrace(); | |
47 | + return null; | |
48 | + }finally { | |
49 | + try { | |
50 | + if(rs != null) { | |
51 | + rs.close(); | |
52 | + } | |
53 | + if(pstmt != null) { | |
54 | + pstmt.close(); | |
55 | + } | |
56 | + if(conn != null) { | |
57 | + conn.close(); | |
58 | + } | |
59 | + } catch (Exception e2) { | |
60 | + e2.printStackTrace(); | |
61 | + } | |
62 | + } | |
63 | + } | |
64 | +} | |
65 | + | |
66 | + | |
67 | + | |
68 | + | |
69 | + | |
70 | + |
+++ WebTest/src/main/java/model/MemberDTO.java
... | ... | @@ -0,0 +1,42 @@ |
1 | +package model; | |
2 | + | |
3 | +public class MemberDTO { | |
4 | + | |
5 | + private int no; | |
6 | + private String name; | |
7 | + private int age; | |
8 | + public int getNo() { | |
9 | + return no; | |
10 | + } | |
11 | + public MemberDTO() { | |
12 | + super(); | |
13 | + } | |
14 | + | |
15 | + @Override | |
16 | + public String toString() { | |
17 | + return "MemberDTO [no=" + no + ", name=" + name + ", age=" + age + ", role=" + role + "]\n"; | |
18 | + } | |
19 | + public void setNo(int no) { | |
20 | + this.no = no; | |
21 | + } | |
22 | + public String getName() { | |
23 | + return name; | |
24 | + } | |
25 | + public void setName(String name) { | |
26 | + this.name = name; | |
27 | + } | |
28 | + public int getAge() { | |
29 | + return age; | |
30 | + } | |
31 | + public void setAge(int age) { | |
32 | + this.age = age; | |
33 | + } | |
34 | + public String getRole() { | |
35 | + return role; | |
36 | + } | |
37 | + public void setRole(String role) { | |
38 | + this.role = role; | |
39 | + } | |
40 | + private String role; | |
41 | + | |
42 | +} |
--- WebTest/src/main/java/servlet/Main.java
+++ WebTest/src/main/java/servlet/Main.java
... | ... | @@ -33,11 +33,13 @@ |
33 | 33 |
response.setCharacterEncoding("UTF-8"); |
34 | 34 |
response.setContentType("text/html; charset=utf-8"); |
35 | 35 |
|
36 |
+ String title = getInitParameter("title"); |
|
37 |
+ |
|
36 | 38 |
PrintWriter out = response.getWriter(); |
37 | 39 |
out.println("<html lang='ko'>"); |
38 | 40 |
out.println("<head>"); |
39 | 41 |
out.println("<meta charset='UTF-8'>"); |
40 |
- out.println("<title>Main Page</title>"); |
|
42 |
+ out.println("<title>" + title + "</title>"); |
|
41 | 43 |
out.println("</head>"); |
42 | 44 |
out.println("<body>"); |
43 | 45 |
out.println("<h3>This is Main Page</h3>"); |
--- WebTest/src/main/java/servlet/MyServlet.java
+++ WebTest/src/main/java/servlet/MyServlet.java
... | ... | @@ -29,19 +29,19 @@ |
29 | 29 |
*/ |
30 | 30 |
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
31 | 31 |
|
32 |
- request.setCharacterEncoding("UTF-8"); //post method korean |
|
33 |
- response.setCharacterEncoding("UTF-8"); //get method korean |
|
34 |
- response.setContentType("text/html; charset=utf-8"); //html contents korean |
|
32 |
+// request.setCharacterEncoding("UTF-8"); //post method korean |
|
33 |
+// response.setCharacterEncoding("UTF-8"); //get method korean |
|
34 |
+// response.setContentType("text/html; charset=utf-8"); //html contents korean |
|
35 | 35 |
|
36 | 36 |
// response.getWriter().append("Served at: ").append(request.getContextPath()); |
37 | 37 |
PrintWriter out = response.getWriter(); |
38 | 38 |
out.println("<html lang='ko'>"); |
39 | 39 |
out.println("<head>"); |
40 |
- out.println("<meta charset='UTF-8'>"); |
|
40 |
+// out.println("<meta charset='UTF-8'>"); |
|
41 | 41 |
out.println("<title>Servlet Test</title>"); |
42 | 42 |
out.println("</head>"); |
43 | 43 |
out.println("<body>"); |
44 |
- out.println("<h3>MyServlet Test</h3>"); |
|
44 |
+ out.println("<h3>MyServlet Test 한글</h3>"); |
|
45 | 45 |
out.println("</body>"); |
46 | 46 |
out.println("</html>"); |
47 | 47 |
|
--- WebTest/src/main/webapp/WEB-INF/web.xml
+++ WebTest/src/main/webapp/WEB-INF/web.xml
... | ... | @@ -9,9 +9,17 @@ |
9 | 9 |
<welcome-file>default.htm</welcome-file> |
10 | 10 |
<welcome-file>default.jsp</welcome-file> |
11 | 11 |
</welcome-file-list> |
12 |
+ <context-param> |
|
13 |
+ <param-name>global</param-name> |
|
14 |
+ <param-value>My WebSite</param-value> |
|
15 |
+ </context-param> |
|
12 | 16 |
<servlet> |
13 | 17 |
<servlet-name>main</servlet-name> |
14 | 18 |
<servlet-class>servlet.Main</servlet-class> |
19 |
+ <init-param> |
|
20 |
+ <param-name>title</param-name> |
|
21 |
+ <param-value>Main Page</param-value> |
|
22 |
+ </init-param> |
|
15 | 23 |
</servlet> |
16 | 24 |
|
17 | 25 |
<servlet> |
... | ... | @@ -21,6 +29,10 @@ |
21 | 29 |
<param-name>name</param-name> |
22 | 30 |
<param-value>홍길동</param-value> |
23 | 31 |
</init-param> |
32 |
+ <init-param> |
|
33 |
+ <param-name>age</param-name> |
|
34 |
+ <param-value>10</param-value> |
|
35 |
+ </init-param> |
|
24 | 36 |
</servlet> |
25 | 37 |
|
26 | 38 |
<servlet> |
--- WebTest/src/main/webapp/test.jsp
+++ WebTest/src/main/webapp/test.jsp
... | ... | @@ -16,7 +16,14 @@ |
16 | 16 |
<h3><%=title %></h3> |
17 | 17 |
<h4><%=title2 %></h4> |
18 | 18 |
<p> |
19 |
- <%=getInitParameter("name") %> |
|
19 |
+ <%=getInitParameter("name") %>의 나이는 |
|
20 |
+ <%=getInitParameter("age") %> 살 입니다. |
|
20 | 21 |
</p> |
22 |
+ <% |
|
23 |
+ pageContext.setAttribute("iam", "Test 1"); |
|
24 |
+ |
|
25 |
+ out.println(pageContext.getAttribute("iam")); |
|
26 |
+ %> |
|
27 |
+ <H3><%=application.getInitParameter("global") %></H3> |
|
21 | 28 |
</body> |
22 | 29 |
</html>(No newline at end of file) |
--- WebTest/src/main/webapp/test2.jsp
+++ WebTest/src/main/webapp/test2.jsp
... | ... | @@ -6,7 +6,8 @@ |
6 | 6 |
<meta charset="UTF-8"> |
7 | 7 |
<title>Insert title here</title> |
8 | 8 |
</head> |
9 |
-<body> |
|
9 |
+<body> |
|
10 | 10 |
<%=getInitParameter("name") %> |
11 |
-</body> |
|
11 |
+ <h4><%=application.getInitParameter("global") %></h4> |
|
12 |
+</body> |
|
12 | 13 |
</html>(No newline at end of file) |
+++ WebTest/src/main/webapp/view/list.jsp
... | ... | @@ -0,0 +1,78 @@ |
1 | +<%@page import="model.MemberDTO"%> | |
2 | +<%@page import="java.util.List"%> | |
3 | +<%@page import="java.util.Map"%> | |
4 | +<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> | |
5 | +<%@ page language="java" contentType="text/html; charset=UTF-8" | |
6 | + pageEncoding="UTF-8"%> | |
7 | +<!DOCTYPE html> | |
8 | +<html> | |
9 | +<head> | |
10 | +<meta charset="UTF-8"> | |
11 | +<title>Insert title here</title> | |
12 | +</head> | |
13 | +<body> | |
14 | +<% | |
15 | + Map<String, Object> map = (Map<String, Object>) request.getAttribute("map"); | |
16 | + List<MemberDTO> list = (List<MemberDTO>) map.get("list"); | |
17 | + int count = (int) map.get("count"); | |
18 | +%> | |
19 | + <table border="1"> | |
20 | + <thead> | |
21 | + <tr> | |
22 | + <th>번호</th> | |
23 | + <th>이름</th> | |
24 | + <th>나이</th> | |
25 | + <th>직위</th> | |
26 | + </tr> | |
27 | + </thead> | |
28 | + <% for(MemberDTO mb : list){ %> | |
29 | + <tr> | |
30 | + <td><%=mb.getNo() %></td> | |
31 | + <td><%=mb.getName() %></td> | |
32 | + <td><%=mb.getAge() %></td> | |
33 | + <td><%=mb.getRole() %></td> | |
34 | + </tr> | |
35 | + <% } %> | |
36 | + </table> | |
37 | + <br /> | |
38 | + <br /> | |
39 | + <br /> | |
40 | + <table border="1"> | |
41 | + <thead> | |
42 | + <tr> | |
43 | + <th>번호</th> | |
44 | + <th>이름</th> | |
45 | + <th>나이</th> | |
46 | + <th>직위</th> | |
47 | + </tr> | |
48 | + </thead> | |
49 | + <c:forEach var="row" items="${map.list}"> | |
50 | + <tr> | |
51 | + <td>${row.no}</td> | |
52 | + <td>${row.name}</td> | |
53 | + <td>${row.age}</td> | |
54 | + <td>${row.role}</td> | |
55 | + </tr> | |
56 | + </c:forEach> | |
57 | + </table> | |
58 | +</body> | |
59 | +</html> | |
60 | + | |
61 | + | |
62 | + | |
63 | + | |
64 | + | |
65 | + | |
66 | + | |
67 | + | |
68 | + | |
69 | + | |
70 | + | |
71 | + | |
72 | + | |
73 | + | |
74 | + | |
75 | + | |
76 | + | |
77 | + | |
78 | + |
+++ WebTest/src/test/java/exam/dbTest.java
... | ... | @@ -0,0 +1,59 @@ |
1 | +package exam; | |
2 | + | |
3 | +import static org.junit.jupiter.api.Assertions.*; | |
4 | + | |
5 | +import java.sql.Connection; | |
6 | +import java.sql.DriverManager; | |
7 | +import java.sql.PreparedStatement; | |
8 | +import java.sql.ResultSet; | |
9 | + | |
10 | +import org.junit.jupiter.api.Test; | |
11 | + | |
12 | +class dbTest { | |
13 | + | |
14 | + @Test | |
15 | + void test() { | |
16 | +// fail("Not yet implemented"); | |
17 | + assertTrue(1==1); //true | |
18 | + assertFalse(1==2); //false | |
19 | + } | |
20 | + | |
21 | + @Test | |
22 | + void classForNameTest() { | |
23 | + try { | |
24 | + Class.forName("com.mysql.jdbc.Driver"); | |
25 | + } catch (Exception e) { | |
26 | + e.printStackTrace(); | |
27 | + fail("Driver Loading Error!!"); | |
28 | + } | |
29 | + } | |
30 | + | |
31 | + @Test | |
32 | + void databaseTest() { | |
33 | + try { | |
34 | + Connection conn = DriverManager.getConnection("jdbc:mysql://db.asin21.com/db_demo07", "demo07", "demo07!"); | |
35 | + PreparedStatement pstmt = conn.prepareStatement("select * from user"); | |
36 | + ResultSet rs = pstmt.executeQuery(); | |
37 | + while(rs.next()) { | |
38 | + System.out.print(rs.getInt("no") + "\t"); | |
39 | + System.out.print(rs.getString("name") + "\t"); | |
40 | + System.out.print(rs.getString("age") + "\t"); | |
41 | + System.out.println(rs.getString("role") + "\t"); | |
42 | + } | |
43 | + | |
44 | + } catch (Exception e) { | |
45 | + e.printStackTrace(); | |
46 | + fail("Fail!! : Database Connention error"); | |
47 | + } | |
48 | + } | |
49 | + | |
50 | +} | |
51 | + | |
52 | + | |
53 | + | |
54 | + | |
55 | + | |
56 | + | |
57 | + | |
58 | + | |
59 | + |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?