这是我第一次写博客,不足之处希望多多谅解。
首先该实例是我学习完hbase之后的总结,都是对hbase的基本操作(即hbase的增、删、改、查);Web方面使用的是Jsp+servlet技术。由于主要目的在于Hbase的操作,因此web页面比较简单,没有设计酷炫的页面。
1.工程环境
实例的工程环境为:jdk1.7+tomcat6+hbase1.2.0。
Tomcat版本有点老了,但不影响使用,大家凑合一下吧。由于没有使用maven创建工程,现在将项目所用jar包也列举一下。这个应该是hbase开发的最小环境了。这些jar包绝大多数都可以在hbase的安装包的lib目录下找到。可以根据自己的实际环境进行替换。
项目采用经典的mvc模式进行编写。
2.登陆功能介绍:
该功能只是我用来复习web相关知识所用。没有将用户名和密码保存到数据库。
login.jsp
-------------------------------------------------------------------------------------
<body>
<div style="width: 300px; height: 400px">
<h1>登录</h1>
<hr />
<p style="font-weight: 900; color: red;">${msg }</p>
<form action="${pageContext.request.contextPath}/LoginServlet"
method="post">
用户名:<input type="text" name="username" value="${user.username }" /><br />
密 码:<input type="password" name="password" value="${user.password }" /><br />
<input type="submit" value="登录" />
</form>
</div>
</body>
LoginServlet.java
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username+":"+password);
if(username.equals("lhs") && password.equals("123")){
//response.sendRedirect("/Hbaseweb/welcom.jsp");
request.getRequestDispatcher("/index.jsp").forward(request, response);
}else{
request.setAttribute("msg", "用户名或密码错误");
request.getRequestDispatcher("/login.jsp").forward(request, response);
}
}
3.关于Hbase的操作
3.1列出hbase中所有的表和列簇
该功能的实现主要是通过hbase的Admin类的listTables()的相关方法实现。其中Servlet类对HttpServlet进行了封装,可以实现一个Servlet实现多个处理方法。
list.jsp
-------------------------------------------------------------------------
<body>
<h3 align="center">客户列表</h3>
<table border="1" width="70%" align="center">
<tr>
<th>序号</th>
<th>表名</th>
<th>列族名</th>
<th>操作</th>
</tr>
<c:forEach items="${requestScope.tables}" var="table">
<tr>
<td>${table.tableId }</td>
<td>${table.table }</td>
<td>${table.columnFamily }</td>
<td><a
href="<c:url value='/tableEdit.jsp?table=${table.table }&columnFamily=${table.columnFamily }'/>">编辑</a>
</td>
</tr>
</c:forEach>
</table>
</body>