📄 site-demo.jsp
字号:
<!-- Onet Forums 网站集成演示 -->
<!--
用法:
1.启动论坛系统
2.将此文件放到站点根目录
3.运行演示,浏览器输入如:http://localhost/onet/site-demo.jsp
-->
<%@ page import="com.onetsoft.base.util.StringUtils" %>
<%@ page import="com.onetsoft.fastjsp.util.ValueParser" %>
<%@ page import="com.onetsoft.forum.*" %>
<%@ page import="com.onetsoft.forum.impl.ForumFactoryImpl" %>
<%@ page import="com.onetsoft.jsp.LinkCons" %>
<%@ page import="com.onetsoft.jsp.LoginHelper" %>
<%@ page import="com.onetsoft.jsp.PageCons" %>
<%@ page import="com.onetsoft.jsp.VisitHelper" %>
<%@ page import="com.onetsoft.jsp.util.StaticLink" %>
<%@ page import="com.onetsoft.tapestry.Visit" %>
<%@ page import="java.util.Collections" %>
<%@ page import="java.util.Iterator" %>
<%@ page import="com.onetsoft.base.security.*"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="com.onetsoft.base.util.IteratorFactory"%>
<%@ page contentType="text/html;charset=utf-8" %>
<%
final UserManager userManager= ForumFactoryImpl.instance().getUserManager();
User admin =userManager.getUser("admin");
Acl adminAcl = AclFactory.getAcl(admin.getID());
ForumFactory adminfactory = ForumFactory.instance(adminAcl);
Zone rootZone = adminfactory.getRootZone();
Visit visit = VisitHelper.getVisit(request);
String verifyCode = visit.getVerifyCode();
/*以下处理发帖和登录过程*/
String operation = request.getParameter("operation");
String subject = StringUtils.trimToEmpty(request.getParameter("subject"));
String body = StringUtils.trimToEmpty(request.getParameter("body"));
String forumID = StringUtils.trimToEmpty(request.getParameter("forumID"));
String username = StringUtils.trimToEmpty(request.getParameter("username"));
String password = StringUtils.trimToEmpty(request.getParameter("password"));
String email = StringUtils.trimToEmpty(request.getParameter("email"));
String reminderQuestion = StringUtils.trimToEmpty(request.getParameter("reminderQuestion"));
String reminderAnswer = StringUtils.trimToEmpty(request.getParameter("reminderAnswer"));
String errorMessage = null;
try {
/*处理发帖过程 begin*/
if ("post".equals(operation)) {
if (StringUtils.isEmpty(subject)) {
throw new NullPointerException("Subject cannot be null!");
}
if (StringUtils.isEmpty(body)) {
throw new NullPointerException("Body cannot be null!");
}
long curforumID = Long.parseLong(forumID);
long userID = SecurityFactory.getAuthManager().authenticate(username, password);
if (userID != -1L && curforumID != -1L) {
Acl acl = AclFactory.getAcl(userID);
ForumFactory factory = ForumFactory.instance(acl);
if (acl.isAllowToCreateThread(curforumID)) {
Forum forum = factory.getForum(curforumID);
ForumMessage message = SupportService.getForumMessageSupport().createForumMessage();
message.setSubject(subject);
message.setBody(body);
message.setForumID(curforumID);
message.setUserID(userID);
message.setAuthor(username);
message.setIP(request.getRemoteAddr());
forum.addThread(message, Collections.EMPTY_MAP, Collections.EMPTY_MAP);
}
}
}
/*处理发帖过程 end*/
/*跳转登录 begin*/
else if ("login".equals(operation)) {
String inputedVerifyCode = request.getParameter("verifyCode");
StaticLink link = new StaticLink(PageCons.Login).appendAction("login").append("username", username).append("password", password)
.append("verifyCode", inputedVerifyCode);
response.sendRedirect(link.getURL());
}
/*跳转登录 end*/
/*本地登录 begin*/
else if ("login_local".equals(operation)) {
boolean autoLogin = ValueParser.parseBoolean(request.getParameter("autoLogin"), false);
int autoLoginDays = 0;
if (autoLogin)
autoLoginDays = 7; //若启用“自动登录”,则设置7天自动登录时间
LoginHelper.loginUser(visit, username, password, autoLogin, autoLoginDays * 24 * 60 * 60, request, response);
} else if ("loginout_local".equals(operation)) {
LoginHelper.logoutUser(request, response);
visit=VisitHelper.getVisit(request);
}
/*本地登录 end*/
/*注册新用户 begin*/
else if ("reg".equals(operation)) {
if(StringUtils.isEmpty(username)|| StringUtils.isEmpty(password) || StringUtils.isEmpty(email)||StringUtils.isEmpty(reminderQuestion)
||StringUtils.isEmpty(reminderAnswer))
{
errorMessage="输入不能为空";
}else{
int emailVisible=0; //0:邮件不公开
int activeValue=com.onetsoft.forum.conf.RegConf.ACTIVE_VALUE_ACTIVED; //已经激活
Map map=new HashMap(1);
map.put("registerIP",request.getRemoteAddr());
userManager.createUser(username,password,email,emailVisible,reminderQuestion,reminderAnswer,activeValue,map);
errorMessage="注册成功";
}
}
/*注册新用户 end*/
} catch (Exception e) {
errorMessage = e.toString();
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>网站集成演示系统</title>
<style>
<!--
.summary {
font-size: 14px;
font-weight: bolder;
color: #000000;
padding: 5px 0px 25px;
}
body, td {
font-size: 12px;
}
.summaryBar {
font-weight: bold;
background-color: #CCCCCC;
padding: 5px 0px 5px 5px;
border-top: 1px solid #999999;
border-bottom: 2px solid #EBEBEB;
}
.titleBar {
font-weight: bold;
background-color: #EFE4E2;
padding: 3px 0px 2px 5px;
border-top: 1px solid #990000;
border-bottom: 2px solid #DFD0C4;
color: #000;
}
-->
</style>
</head>
<body>
<div align="center" class="summary" style="font-size:14px; ">Onet Forums 网站集成演示</div>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100%"><div class="summaryBar">论坛区列表 </div>
<table width="15%" border="0" cellspacing="1" cellpadding="2">
<tr>
<% for (Iterator iter = rootZone.getRecursiveZones(); iter.hasNext();) {
Zone zone = (Zone) iter.next();
%>
<td>
<a href="<%=new StaticLink(PageCons.Index).append(LinkCons.zoneID,zone.getID())%>" target="_blank"><%=zone.getName()%></a>
</td>
<%}%>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100%"><div class="summaryBar">论坛列表 </div>
<table width="15%" border="0" cellspacing="1" cellpadding="2">
<tr>
<% Forum firstForum = null;
for (Iterator iter = rootZone.getRecursiveForums(); iter.hasNext();) {
Forum forum = (Forum) iter.next();
if (firstForum == null) {
firstForum = forum;
}
%>
<td>
<a href="<%=new StaticLink(PageCons.Threads).append(LinkCons.forumID,forum.getID())%>" target="_blank"><%=forum.getName()%></a>
</td>
<%}%>
</tr>
</table>
</td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td colspan="4"><div class="summaryBar">相关排行(以下第一个论坛示例)</div></td>
</tr>
<%if (firstForum != null) {%>
<tr>
<td width="25%" valign="top">
<table width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<td class="titleBar">最新帖子</td>
</tr>
<%
Iterator iter = firstForum.getThreads(10);
%>
<% while (iter.hasNext()) {
ForumThread thread = (ForumThread) iter.next();
%>
<tr>
<td>
<a href="<%=new StaticLink(PageCons.Messages).append(LinkCons.messageID, thread.getRootID())%>" target="_blank"><%=thread.getName()%></a> </td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -