SSH action+struts.xml+jsp

DuestionsAction 控制类

package cn.action;
import java.util.Date;
import java.util.List;
import cn.biz.DuestionsBiz;
import cn.entity.Answers;
import cn.entity.Duestions;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
public class DuestionsAction extends ActionSupport {
	private DuestionsBiz duestionsBiz;
	private List duestions;
	private List answers;
	private Answers answer;
	private Duestions duestion;
	private Integer id;
	/**
	 * 显示列表
	 * @return
	 * @throws Exception
	 */
	public String getAll() throws Exception{
		/*
		 * 如果 id 不为空,代表是从 findDetatil.acton 传来的数据
		 * 第一步:根据 id 获取问题表的数据
		 * 第二步:插入应答表的数据,主键是问题表
		 * 第三步:设置问题表的应答次数,和最新的时间
		 * 第四步:修改问题表数据
		 */
		if(id != null){
			duestion = duestionsBiz.findById(id);
			duestionsBiz.insert(new Answers(duestion, answer.getAnscontent(), new Date()));
			duestion.setAnsewercount(duestionsBiz.findAnswersList(id).size());
			duestion.setLastmodidfied(new Date());
			duestionsBiz.update(duestion);
			id = null;//清空,要不然重复插入应答表的数据
		}
		//最后,显示列表
		duestions = duestionsBiz.findAll();
		return SUCCESS;
	}
	/**
	 * 应答表列表
	 * @return
	 * @throws Exception
	 */
	public String findDetatil() throws Exception{
		//传过的 id 来获取数据
		if(id != null){
		duestion = duestionsBiz.findById(id);
		answers = duestionsBiz.findAnswersList(id);
		}
		return SUCCESS;
	}
	/**
	 * 插入问题表数据
	 * @return
	 * @throws Exception
	 */
	public String doAdd() throws Exception{
		if(duestion!=null){
			duestionsBiz.add(new Duestions(duestion.getTitle(), duestion.getDetaildesc(), 0, new Date()));
		}
		return SUCCESS;
	}
	public DuestionsBiz getDuestionsBiz() {
		return duestionsBiz;
	}
	public void setDuestionsBiz(DuestionsBiz duestionsBiz) {
		this.duestionsBiz = duestionsBiz;
	}
	public List getDuestions() {
		return duestions;
	}
	public void setDuestions(List duestions) {
		this.duestions = duestions;
	}
	public Duestions getDuestion() {
		return duestion;
	}
	public void setDuestion(Duestions duestion) {
		this.duestion = duestion;
	}
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public List getAnswers() {
		return answers;
	}
	public void setAnswers(List answers) {
		this.answers = answers;
	}
	public Answers getAnswer() {
		return answer;
	}
	public void setAnswer(Answers answer) {
		this.answer = answer;
	}
}

 

struts.xml 配置




	
	
	
	
		
		
			/list.jsp
		
		
		
			/detail.jsp
		
		
		
			/index.jsp
		
	
    

 

index.jsp 页面

<%@ 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 + "/";
%>




My JSP 'index.jsp' starting page


	
	


 

list.jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>




在线回答



	

在线回答

我要提问

class="tdBg">
序号 问题 回答次数 最后修改
 

 

效果图:
SSH action+struts.xml+jsp_第1张图片
 

detail.jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>




我来回答
  


	
问题:
问题描述:
网友回答
我来回答
返回

 

效果图:
SSH action+struts.xml+jsp_第2张图片
 

question.jsp 页面

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>




我要提问
  


	

我要提问

返回首页

问题:
问题描述:
  返回

 

效果图:
SSH action+struts.xml+jsp_第3张图片
 

 

 

你可能感兴趣的:(item10,问答)