我使用MVC2做了一些页面。但它无法显示模型组件所称的所有数据。
所以我尝试使用MVC1创建页面。它奏效了。
我想知道为什么2页不同。为什么会这样?
//这是视图 - MVC1(照片底部 - AdminMemberList.jsp),MVC(照片中的顶部 - AdminMemberList.do)
//这是模型输出数据的结果(在控制台中) - 相同的MVC1和MVC2
Member [id=aaaa, point=50, birthday=1923-01-01, email=dwd@google.com]
Member [id=admin, point=40, birthday=1999-01-03, email=ks@nad.com]
Member [id=bbbb, point=20, birthday=1454-09-03, email=bbb]
Member [id=bbbbbb, point=10, birthday=1970-01-01, email=bb@bd.com]
Member [id=david, point=10, birthday=1990-12-30, email=dkakd@gmd.com]
Member [id=davidhong, point=10, birthday=1967-03-09, email=hong@dsd.com]
Member [id=happy, point=30, birthday=1983-03-02, email=gg@gg.com]
Member [id=imyourman, point=10, birthday=1978-02-02, email=kakd@ddl.com]
Member [id=kaaf, point=10, birthday=1978-07-03, email=akd@em]
Member [id=solomon, point=10, birthday=1989-09-12, email=solomon@gmail.com]
Member [id=sunny, point=10, birthday=1985-04-02,email=akdfjl@em.com]
Member [id=xxxxxx, point=10, birthday=1982-01-01, email=del@do.com]
// AdminMemberList.jsp - 这是视图组件:MVC1& MVC2相同
<body style="padding-top: 55px;">
<jsp:include page="ConnectDB.jsp"/>
<jsp:include page="CommonTopmenu.jsp" flush="false"/>
<div class="container-fluid">
<div class="row">
<div>
<!-- <div id="main" class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">-->
<h4>Member Info</h4>
<button type="button" id="ajaxDeleteMemberData" class="btn btn-sm btn-primary">Remove</button>
<button type="button" id="ajaxUpdateMemberData" class="btn btn-sm btn-primary">Update</button>
<span>Total : ${countMember} people</span>
<table class="table table-hover" id="tabletest">
<thead>
<tr>
<th><input type="checkbox" id="changeChecking" name="changeChecking"></th>
<th>ID</th> <th>Point</th>
<th>Birthday</th> <th>Email</th> <th>Regdate</th> <th>Password</th>
</tr>
</thead>
<c:forEach items="${articleList}" var="article">
<tbody>
<tr>
<td><input type="checkbox" class="tr_check" name="check2"></td>
<td>${article.id}</td>
<td ><input type="number" class="point" name="${article.id}" min="0" max="300" step="10"
value="${article.point}"/></td>
<td>${article.birthday}</td>
<td>${article.email}</td>
<td>${article.regdate}</td>
<td><input type="text" name="${article.id}" value="${article.password}"/>
<input type="button" class="btnChange" name="${article.id}" value="Edit">
</td>
</tr>
</tbody>
</c:forEach>
</table>
</div>
</div>
</div>
</body>
// AdminMemberListAction.do - 这是模型组件: MVC2
public class AdminMemberListAction implements CommandAction {
@Override
public String requestPro(HttpServletRequest request,
HttpServletResponse response) throws Throwable {
List<Board> list = null;
int countMember =0;
String res="orm/mybatis/config.xml";
try{
InputStream is = Resources.getResourceAsStream(res);
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
SqlSession sqlSession = factory.openSession();
list = sqlSession.selectList("getMemberList");
sqlSession.close();
}catch(IOException ie){
System.out.println(ie.getMessage());
}
countMember = list.size();
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
request.setAttribute("articleList", list);
request.setAttribute("countMember", countMember);
return "AdminMemberList.jsp";
}
}
// ConnectDB.jsp - 这是模型组件: MVC1
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%
try {
String driverName = "org.mariadb.jdbc.Driver";
String url = "jdbc:mariadb://localhost:3306/team";
ResultSet rs = null;
Class.forName(driverName);
Connection con = DriverManager.getConnection(url,"id","password");
Statement stmt = con.createStatement();
String sql = "SELECT * from member";
rs = stmt.executeQuery(sql);
ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> hm = new HashMap<String, Object>();
while(rs.next()){
hm = new HashMap<String, Object>();
hm.put("id", rs.getString("id"));
hm.put("point", rs.getString("point"));
hm.put("birthday", rs.getString("birthday"));
hm.put("email", rs.getString("email"));
list.add(hm);
}
request.setAttribute("articleList", list);
con.close();
}catch (Exception e) {
out.println("Oracle Database Connection Something Problem. <hr>");
out.println(e.getMessage());
e.printStackTrace();
}
%>