Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hong #420

Merged
merged 3 commits into from
Nov 10, 2016
Merged

hong #420

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902110/HomeServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package edu.hzu.javaweb.labs.se1414080902110;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import bean.Messay;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name = "HomeServlet", urlPatterns = { "/homepage" })
public class HomeServlet extends HttpServlet {
private Connection conn1, conn2;
private PreparedStatement pstmt1, pstmt2;
private ResultSet rs1, rs2;

public HomeServlet() {
super();
}

public void destroy() {
super.destroy();
}

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
JDBCconnection connection = new JDBCconnection();
conn1 = connection.connection();
conn2 = connection.connection();
String sql1 = "select * from essay where is_del=1";
pstmt1 = conn1.prepareStatement(sql1);
rs1 = pstmt1.executeQuery();
List<Messay> messayList = new ArrayList<Messay>();
while (rs1.next()) {
String sql2 = "select user_name,user_photo from user where user_id=?";
pstmt2 = conn2.prepareStatement(sql2);
pstmt2.setInt(1, rs1.getInt("user_id"));
rs2 = pstmt2.executeQuery();
if (rs2.next()) {
messayList.add(new Messay(rs1.getInt("essay_id"),
rs1.getString("essay_title"),
rs1.getString("classify"),
rs1.getInt("click"),
rs2.getString("user_name")));
}
}
request.setAttribute("messay", messayList);
request.getRequestDispatcher("/index/homepage.jsp").forward(
request, response);
} catch (Exception e) {
e.printStackTrace();
}
}

public void init() throws ServletException {
// Put your code here
}

}
58 changes: 58 additions & 0 deletions jweb/src/edu/hzu/javaweb/labs/se1414080902110/Messay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package bean;

public class Messay {
private int essay_Id, click;
private String essay_title, classify, user_name;

public Messay() {
}

public Messay(int essay_Id, String essay_title, String classify, int click, String user_name) {
this.essay_Id = essay_Id;
this.essay_title = essay_title;
this.classify = classify;
this.click = click;
this.user_name = user_name;
}

public int getEssay_Id() {
return essay_Id;
}

public void setEssay_Id(int essay_Id) {
this.essay_Id = essay_Id;
}

public String getEssay_title() {
return essay_title;
}

public void setEssay_title(String essay_title) {
this.essay_title = essay_title;
}

public String getClassify() {
return classify;
}

public void setClassify(String classify) {
this.classify = classify;
}

public int getClick() {
return click;
}

public void setClick(int click) {
this.click = click;
}

public String getUser_name() {
return user_name;
}

public void setUser_name(String user_name) {
this.user_name = user_name;
}

}
142 changes: 142 additions & 0 deletions jweb/web/1414080902110/homepage.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML >
<html>
<head>
<title>音乐论坛-音乐爱好者的聚集地</title>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<link
href="http://cdn.bootcss.com/bootstrap/2.3.2/css/bootstrap.min.css"
rel="stylesheet" />
<script src="http://cdn.bootcss.com/bootstrap/2.3.2/js/bootstrap.min.js"></script>
<style type="text/css">
.header {
width: 100%;
background: #f5f2f2;
height: 25px;
}

.header .targer {
width: 300px;
height: 250px;
position:absolute;
margin-left: 1000px;
}

.header a {
text-decoration: none;
color: #d9534f;
font-size: 14px;
}

.header a:hover {
background: #d9534f;
color: white;
border-radius: 2px;
}

.adv {
margin: 0 auto;
}

.line {
width: 100%;
height: 1px;
background: #f5f2f2;
}

.content {
width: 80%;
margin: 0 auto;
}

.content button {
margin-top: 3px;
}

.content .list {
width: 100%;
height: auto;
margin-top: 3px;
border-radius: 3px;
border: 1px solid #d9534f;
}

.content .list_one {
width: 95%;
height: 40px;
line-height: 40px;
margin-top: 3px;
border-bottom: 1px dotted #d9534f;
margin: 0 auto;
}

.content a {
text-decoration: none;
font-family: 微软雅黑;
font-size: 16px;
font-weight: bolder;
color: #575656;
}

.content a:hover {
text-decoration: underline;
}

.content .author {
float: right;
}

.content .author .line {
color: #d9534f;
}

.foot {
width: 100%;
height: 40px;
background: #f5f2f2;
text-align: center;
line-height: 40px;
}
</style>
</head>

<body>
<div class="header">
<div class="targer">
<c:if test="${loginUserAccount!=null}">
<i class="icon-user"></i>
<a>当前用户名:</a><c:out value="${sessionScope.loginUserAccount }"></c:out>|
</c:if>
<i class="icon-headphones"></i> <a href="./index.jsp">登录</a>|
<i class="icon-home"></i> <a href="#">注册</a>
</div>
</div>
<div class="adv">
<img src="./images/adv.jpg">
</div>
<div class="line"></div>
<div class="content">
<button class="btn btn-danger">发布文章</button>
<div class="list">
<c:forEach var="essay" items="${messay}">
<div class="list_one">
<i class="icon-tag"></i><a href="#">${essay.essay_title}</a>
<div class="author">
<span>类别:${essay.classify}</span><span class="line">|</span><span>作者:${essay.user_name}</span><span
class="line">|</span><span>阅读量:${essay.click}</span>
</div>
</div>
</c:forEach>
</div>
</div>
<div class="foot">&copy;2016&nbsp;hong版权所有</div>
</body>
</html>