天乙社区8.5.0Beta2
一、简介:
天乙社区是一套基于JAVA技术的网络虚拟社区,采用了Hibernate+Spring+Struts的轻量级J2EE框架.
1、全文检索:天乙社区6.0采用Lucene全文检索,并支持完全国际化多语言的全文检索。
2、MVC框架:天乙社区6.0继续了5.x的Struts框架,但经过优化,WEB端更加简洁高效。
3、集群支持:系统可以运行在集群上。
4、功能方面:大大加强了管理功能,用户可以多样化的定制系统的各项信息,包括用户级别、封锁IP、过滤字等等,论坛功能上主要增加了投票帖、上传附件类型多样、帖子中显示用户信息等等功能等。
下载地址: http://www.laoer.com/
二、功能分析:
1.web.xml:
在web.xml文件中,定义的filter和listener是有顺序的,涉及到对象的初始化顺序以及引用。特别注意的有如下几个配置:
Spring配置文件:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/action-servlet.xml</param-value> </context-param>
<servlet> <servlet-name>authimg</servlet-name> <servlet-class>com.laoer.bbscs.web.servlet.AuthImg</servlet-class> </servlet> <servlet-mapping> <servlet-name>authimg</servlet-name> <url-pattern>/authimg</url-pattern> </servlet-mapping>
<%@taglib uri="/WEB-INF/bbscs.tld" prefix="bbscs"%><html> <body> ...... <bbscs:face value="%{userSession.id}"/> ...... </body></html>
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"><taglib><tlib-version>2.2.3</tlib-version><jsp-version>1.2</jsp-version><short-name>bbscs</short-name><uri>/bbscs</uri><display-name>"BBSCS Tags"</display-name>...... <tag><name>face</name><tag-class>com.laoer.bbscs.web.taglib.UserFaceTag</tag-class><body-content>empty</body-content><attribute><name>value</name><required>true</required><rtexprvalue>true</rtexprvalue></attribute></tag></taglib>
public class UserFaceTag extends BbscsComponentTagSupport {/** * */private static final long serialVersionUID = -2113974447691755459L;public UserFaceTag() {// TODO 自动生成构造函数存根}private String value;public String getValue() {return value;}public void setValue(String value) {this.value = value;}@Overridepublic Component getBean(ValueStack stack, PageContext pageContext) {// TODO 自动生成方法存根return new UserFace(stack, pageContext);}protected void populateParams() {super.populateParams();UserFace tag = (UserFace) component;tag.setValue(value);}}
public abstract class BbscsComponentTagSupport extends StrutsBodyTagSupport {protected Component component;public abstract Component getBean(ValueStack stack, PageContext pageContext);public int doEndTag() throws JspException {component.end(pageContext.getOut(), getBody());component = null;return EVAL_PAGE;}public int doStartTag() throws JspException {component = getBean(getStack(), pageContext);Container container = Dispatcher.getInstance().getContainer();container.inject(component);populateParams();boolean evalBody = component.start(pageContext.getOut());if (evalBody) {return component.usesBody() ? EVAL_BODY_BUFFERED : EVAL_BODY_INCLUDE;} else {return SKIP_BODY;}}protected void populateParams() {component.setId(id);}public Component getComponent() {return component;}}
public class UserFace extends Component {private PageContext pageContext;private String facePicName = "images/defaultFace.gif";private String value;public String getValue() {return value;}public void setValue(String value) {this.value = value;}public UserFace(ValueStack stack, PageContext pageContext) {super(stack);this.pageContext = pageContext;}public boolean start(Writer writer) {boolean result = super.start(writer);if (value == null) {value = "top";} else if (altSyntax()) {if (value.startsWith("%{") && value.endsWith("}")) {value = value.substring(2, value.length() - 1);}}String userId = "";Object idObj = this.getStack().findValue(value);if (idObj != null) {userId = (String) idObj;}StringBuffer sb = new StringBuffer();if (StringUtils.isBlank(userId)) {sb.append("<img src="");sb.append(facePicName);sb.append("" alt="Face" />");try {writer.write(sb.toString());} catch (IOException e) {e.printStackTrace();}return result;} else {if (userId.startsWith(Constant.GUEST_USERID)) { // 游客sb.append("<img src="");sb.append(facePicName);sb.append("" alt="Face" />");} else { // 正常用户WebApplicationContext wc = WebApplicationContextUtils.getWebApplicationContext(this.pageContext.getServletContext());UserService us = (UserService) wc.getBean("userService");UserInfoSimple uis = us.getUserInfoSimple(userId);if (uis.getHavePic() == 1 && !uis.getPicFileName().equals("-")) {sb.append("<a href="");sb.append(BBSCSUtil.getUserWebPath(uis.getId()));sb.append(uis.getPicFileName());sb.append("" target="_blank">");sb.append("<img src="");sb.append(BBSCSUtil.getUserWebPath(uis.getId()));sb.append(uis.getPicFileName());sb.append(Constant.IMG_SMALL_FILEPREFIX);sb.append("" alt="Face" border="0" class="pic1"/>");sb.append("</a>");} else {sb.append("<img src="");sb.append(facePicName);sb.append("" alt="Face" />");}}try {writer.write(sb.toString());} catch (IOException e) {e.printStackTrace();}}return result;}}