`
chaoyi
  • 浏览: 291275 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

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> duestions;
	private List<Answers> 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<Duestions> getDuestions() {
		return duestions;
	}
	public void setDuestions(List<Duestions> 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<Answers> getAnswers() {
		return answers;
	}
	public void setAnswers(List<Answers> answers) {
		this.answers = answers;
	}
	public Answers getAnswer() {
		return answer;
	}
	public void setAnswer(Answers answer) {
		this.answer = answer;
	}
}

 

struts.xml 配置

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" 
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
	<constant name="struts.i18n.encoding" value="utf-8"></constant>
	<constant name="struts.ui.theme" value="simple"></constant>
	<constant name="struts.configuration.xml.reload" value="true"></constant>
	<package name="cn.action" extends="struts-default" namespace="/">
		<!-- 显示列表 -->
		<action name="getAll" class="cn.action.DuestionsAction" method="getAll">
			<result name="success">/list.jsp</result>
		</action>
		<!-- 查看应答 -->
		<action name="findDetatil" class="cn.action.DuestionsAction"
			method="findDetatil">
			<result name="success">/detail.jsp</result>
		</action>
		<!-- 添加问题 -->
		<action name="doAdd" class="cn.action.DuestionsAction" method="doAdd">
			<result name="success">/index.jsp</result>
		</action>
	</package>
</struts>    

 

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 + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
</head>
<body>
	<!-- 跳转页面 -->
	<c:redirect url="getAll.action" />
</body>
</html>

 

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 + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>在线回答</title>
<style type="text/css">
*{ margin:0; padding:0; }  
body{ font-family:"宋体"; color:#333; font-size:14px; background:#fff;}  
a{ color:#069; text-decoration:underline;}  
a:hover{ color:#f60; text-decoration:underline;}  
h3{ text-align:center; line-height:40px;}
p{ text-align: center; height: 23px;}  
table{ margin:0 auto; line-height:23px;}  
table tr th{ background:#B8860B;}  
table tr td{ padding:0 8px;}  
table .tdBg td{ background:#999}  
</style>
</head>
<body>
	<div style=" padding: 8px; width: 480px; margin: 0 auto;">
		<h3>在线回答</h3>
		<p>
			<a href="question.jsp">我要提问</a>
		</p>
		<table border="1">
			<tr>
				<th>序号</th>
				<th>问题</th>
				<th>回答次数</th>
				<th>最后修改</th>
			</tr>
			<s:iterator value="duestions" status="st">
			<tr <s:if test="#st.even">class="tdBg"</s:if>>
				<td><s:property value="id"></s:property></td>
				<td><a href="findDetatil.action?id=<s:property value='id'/>">
				<s:property value="title"></s:property></a></td>
				<td><s:property value="ansewercount"></s:property></td>
				<td>&nbsp;<s:date name="lastmodidfied" format="yyyy-MM-dd"></s:date></td>
			</tr>
			</s:iterator>
		</table>
	</div>
</body>
</html>

 

效果图:

 

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 + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>我来回答</title>
<style type="text/css">  
*{ margin:0; padding:0; }  
body{ font-family:"宋体"; color:#333; font-size:14px; background:#fff;}  
table{ margin:0 auto; line-height:23px;}   
table tr td{ padding:0 8px;} 
table tr .tdbg{ background: #999;} 
</style>  
</head>
<body>
	<div style=" padding: 8px; width: 480px; margin: 0 auto;">
		<form action="getAll.action" method="post">
			<table border="1">
				<tr><td>问题:</td><td class="tdbg">
				<s:property value="duestion.title"></s:property></td></tr>
				<tr><td>问题描述:</td><td class="tdbg">
				<s:property value="duestion.detaildesc"></s:property></td></tr>
				<s:iterator value="answers">
				<tr><td>网友回答</td><td class="tdbg">
					<s:property value="anscontent"></s:property>
					<br><s:date name="ansdate" format="yyyy-MM-dd"></s:date>
				</td></tr>
				</s:iterator>
				<tr><td>我来回答</td><td>
					<input type="hidden" name="id" value="<s:property value='id'/>">
					<input type="text" name="answer.anscontent"></td></tr>
				<tr><td><a href="index.jsp">返回</a></td><td><input type="submit"></td></tr>
			</table>
		</form>
	</div>
</body>
</html>

 

效果图:

 

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 + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>我要提问</title>
<style type="text/css">  
body{ font-family:"宋体"; color:#333; font-size:14px; background:#fff;}  
a{ color:#069; text-decoration:underline;}  
a:hover{ color:#f60; text-decoration:underline;}  
h3{ text-align:center; line-height:40px;}
p{ text-align: center;}  
</style>  
</head>
<body>
	<div style=" width: 300px; margin: 0 auto;">
		<form action="doAdd.action" method="post">
			<h3>我要提问</h3>
			<p><a href="index.jsp">返回首页</a></p>
			<table>
				<tr><td>问题:</td><td><input type="text" name="duestion.title"></td></tr>
				<tr><td>问题描述:</td><td><input type="text" name="duestion.detaildesc"></td></tr>
				<tr><td></td><td><input type="submit" value="保存问题">
				&nbsp;&nbsp;<a href="index.jsp">返回</a></td></tr>
			</table>
		</form>
	</div>
</body>
</html>

 

效果图:

 

 

 

  • 大小: 36.1 KB
  • 大小: 32.1 KB
  • 大小: 25.5 KB
分享到:
评论

相关推荐

    JAVA SSH青协志愿服务管理系统源码.rar

    Struts+srping+Hibernate开发青协志愿服务管理系统 数据库 mysql(关系型数据库) 前台技术 JSP(css,js,...WEB-INF (lib+jsp+*.xml) applicationContext.xml 中心配置文件 web.xml 项目配置文件 项目一些基本配置参数

    JAVA SSH青协志愿服务管理系统源码

    Struts+srping+Hibernate开发青协志愿服务管理系统 数据库 mysql(关系型数据库) ...WEB-INF (lib+jsp+*.xml) applicationContext.xml 中心配置文件 web.xml 项目配置文件 项目一些基本配置参数 127.0

    java ssh志愿服务管理系统源码

    WEB-INF (lib+jsp+*.xml) applicationContext.xml 中心装备文件 web.xml 项目装备文件 项目一些基本装备参数 127.0.0.1:8080/zyfw/index.action 普通用户zyz1 123456 http://127.0.0.1:8080/zyfw/admin/login.jsp ...

    SSH代码生成工具 SSH代码生成器

    JSP文件--&gt; 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--&gt; 业务Action.java和导出Excel的Action等 VO --&gt; bean.java及 bean.hbm.xml配置文件 Service --&gt; Service接口定义类 ...

    AutoCode代码生成器【SSH版】

    JSP文件--&gt; 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--&gt; 业务Action.java和导出Excel的Action等 VO --&gt; bean.java及 bean.hbm.xml配置文件 Service --&gt; Service接口定义类 ...

    ssh代码生成器轻松、快捷

    JSP文件--&gt; 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--&gt; 业务Action.java和导出Excel的Action等 VO --&gt; bean.java及 bean.hbm.xml配置文件 Service --&gt; Service接口定义类 DAO --...

    AutoCode代码生成器(SSH版)

    JSP文件--&gt; 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--&gt; 业务Action.java和导出Excel的Action等 VO --&gt; bean.java及 bean.hbm.xml配置文件 Service --&gt; Service接口定义类 ...

    SSH2(spring3.2+strust2.3.4+hibernate4.2)框架演示代码

    SSH2(Spring + Struts2 + Hibernate)是一个流行的Java Web开发框架...struts.xml:Struts2的配置文件,定义Action和Result等。 Action类:处理用户请求和业务逻辑。 JSP页面:展示用户界面。 业务逻辑层(Spring)

    struts2.1宝典

    目录 ...struts2表单标签 1 1、struts资源文件中文解决...SSH Struts+Spring+Hibernate整合 38 创建WEB工程 39 添加Struts2.1开发支持 39 添加Spring开发支持 39 添加Hibernate支持 40 添加Jar包 42 修改Web.xml文件, 42

    SSH整合案例-商品管理.rar

    3.6.编辑struts.xml,配置请求和页面转发路径 3.7.编辑applicationContext.xml, dao注入sessionFactory,service注入dao,action注入service。实现Spring IoC配置 4 各模块具体实现 4.1 登录模块

    Struts2入门教程(全新完整版)

    (2).struts.xml文件 4 (3).struts.properties(参default.properties) 4 (4)struts-default.xml 4 (5)其它配置文件 4 4.让MyEclipse提示xml信息 4 5.如何使用alt+/提示 4 6.实例 4 7.开启struts2自带的...

    spring考试通过必备材料.docx

    在struts.xml中配置页面跳转关系, 21 在applicationContext.xml中配置类之间的调用关系, 22 通知 23 通知文件MyAdvice,schema方法的通知 23 在applicationContext.xml中配置通知--通知文件logAdvice 25 引用AOP的...

    SSH开发纪要整合解决四大问题(中文、jar包冲突、延时加载、模块化)文档

    &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"&gt; &lt;struts-...

    一个非常简单的SSH整合

    struts2+hibernate4+spring3的整合 步骤:a. 创建数据库表 userinfo b. 创建web工程,导入支持 c.... d.... jsp --&gt; action --&gt;... e.配置spring 的applicationContext.xml ...配置struts.xml g.编写页面

    struts2.4+spring3.1+hibernate4.1的SSH框架

     系统的基本业务流程是: 在表示层中,首先通过JSP页面实现交互界面,负责传送请求(Request)和接收响应(Response),然后Struts根据配置文件(struts-config.xml)将ActionServlet接收到的Request委派给相应的Action...

    SSH架构优缺点分析.rar

    本资料详细介绍了SSH架构的优缺点,可作为面试资料备用! 常说的好处 开源 常说的坏处 配置文件过大我就不提了 struts 优点: 收集,验证表单数据相比传统servlet简单 优雅的实现可配置的请求转发 ...

Global site tag (gtag.js) - Google Analytics