PBQA_BBS(1.0)版本

当初做毕业设计的时候,由于技术什么的非常菜鸟,只用到了JSP+Servlet,技术含量比较低,而且代码写的一团糟,非常不容易阅读, 准备改善,加入struts框架。

<%@page import="com.freedom.util.ConnectionDB"%>
<%@page import="com.freedom.method.*"%>
<%@ page language="java"
	import="java.util.*,com.freedom.bean.*,com.freedom.method.*"
	pageEncoding="utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>编程交流论坛</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="WebStyle.css">
</head>

<body>
	<jsp:include page="head.jsp"></jsp:include>
	<!-- 這是登錄模塊,判斷用戶是否登錄,顯示不同的信息 -->
	<div id="login">
		<%
			request.setCharacterEncoding("utf-8");
			response.setCharacterEncoding("utf-8");
			String userName = (String) session.getAttribute("userName");
			if (userName == null) {
		%>
		您好,游客,请<a href="login.jsp">登录</a>&nbsp;&nbsp;或者 <a href="register.jsp">注册</a>
		<%
			} else {
		%>
		您好,<%=userName%>,欢迎光临编程交流论坛<a href="ExitServlet">退出</a>
		<%
			}
		%>
	</div>
	<!-- 查看某个父板块的处理 -->
	<%
		String nav_id = request.getParameter("nav_id");
		String sql = null;
		String sql2 = null;
		if (nav_id != null) {
			sql = "select * from navigation_details where nav_id = "
					+ nav_id;
			sql2 = "select * from navigation where nav_id = '" + nav_id
					+ "';";
			String nav_name = GetNavNameMethod.queryNavName(nav_id);
	%>
	<!-- 这是现实当前位置的模块 -->
	<div id="location">
		<span>您当前的位置:&nbsp;&nbsp;</span> <a href="index.jsp">编程交流论坛</a>&nbsp;&nbsp;→&nbsp;&nbsp;『<%=nav_name%>』
	</div>
	<!-- 沒有查看某个父板块的处理 -->
	<%
		} else {
			sql = "select * from navigation_details order by nav_id";
			sql2 = "select * from navigation order by nav_id";
	%>
	<div id="location">
		<span>您当前的位置:&nbsp;&nbsp;</span><a href="index.jsp">编程交流论坛</a>
	</div>
	<%
		}
		List<NavDetailBean> navDetailBeanList = new LinkedList<NavDetailBean>();
		navDetailBeanList = NavDetailMethod.query(sql);
		List<NavBean> navBeanList = new LinkedList<NavBean>();
		navBeanList = NavMethod.query(sql2);
	%>
	<!-- 显示每日一言部分 -->
	<div id="saying"><%=Saying.getSingleString()%></div>
	<div class="mn">
		<%
			int index = 0;
			for (NavBean n : navBeanList) {
		%>
		<div class="nav">
			<span><a href="index.jsp?nav_id=<%=n.getNav_id()%>"><%=n.getNav_name()%></a>
			</span>
		</div>
		<%
			int count = 0;
				for (NavDetailBean n2 : navDetailBeanList) {
					if (n.getNav_id() == n2.getNav_id()) {
						count++;
					}
				}
		%>
		<div class="item">
			<table cellpadding="0" cellspacing="0">
				<tbody>
					<%
						for (int i = 0; i < count; i++) {
								if (i % 2 == 0) {
					%>
					<tr>
						<%
							}
									NavDetailBean nav = navDetailBeanList.get(index++);
						%>
						<%
							if ((count % 2 == 0 && i + 2 >= count)
											|| (count % 2 != 0 && i + 1 >= count)) {
						%>
						<td class="items" style="border-bottom-style:none">
							<%
								} else {
							%>
						
						<td class="items">
							<%
								}
							%> <img src=<%=nav.getItem_img()%>>
							<dl>
								<dt>
									<a
										href="GetCategoryDetailsServlet?item_id=<%=nav.getItem_id()%>"><%=nav.getItem_name()%></a>
								</dt>
								<dd><%=nav.getDescription()%></dd>
							</dl></td>
						<%
							if (i % 2 != 0 || i == count - 1) {
						%>
					</tr>
					<%
						}
							}
					%>
				</tbody>
			</table>
		</div>
		<%
			}
		%>
	</div>
	<jsp:include page="foot.jsp"></jsp:include>
</body>
</html>



啊啊啊,当初怎么这么写的代码啊啊啊啊,没用到JSTL的控制标签,夹杂了大量的Java代码 希望发布struts版本的时候能有所改善

你可能感兴趣的:(bbs)