FavAction 控制类
package cn.action; import java.util.List; import org.apache.struts2.ServletActionContext; import cn.biz.FavBiz; import cn.biz.TagBiz; import cn.entity.Favorite; import cn.entity.Tag; import com.opensymphony.xwork2.ActionSupport; @SuppressWarnings("serial") public class FavAction extends ActionSupport { private FavBiz favBiz;//收藏 private TagBiz tagBiz;//标记 private Favorite fav; private Tag tag; private List<Favorite> favList; private List<Tag> tagList; private List<String> urlList; private String type; /* * 到 add.jsp 页面去 */ public String toAdd() throws Exception{ return SUCCESS; } /* * 添加收藏 * */ public String doAdd() throws Exception{ System.out.println(fav); favBiz.add(fav); System.out.println("2"+fav); ServletActionContext.getResponse().setContentType("text/html;charset=utf-8"); String s = "<script>alert('添加成功');window.close();</script>"; ServletActionContext.getResponse().getWriter().write(s); System.out.println("3"+fav); return null; } /* * 到显示列表页面 * */ public String toList() throws Exception{ tagList = this.tagBiz.search(null); //为空,则表示查询所有的 if(null==type || "".equals(type)){ type="-1"; } //因为通过 url 传递汉字,所以要解码 type = new String(type.getBytes("iso-8859-1"),"utf-8"); System.out.println(type); favList = this.favBiz.search(type); return SUCCESS; } /* * 到显示云页面 * */ public String toCloud() throws Exception{ tagList = this.tagBiz.search(null); return SUCCESS; } public String getType() { return type; } public void setType(String type) { this.type = type; } public FavBiz getFavBiz() { return favBiz; } public void setFavBiz(FavBiz favBiz) { this.favBiz = favBiz; } public TagBiz getTagBiz() { return tagBiz; } public void setTagBiz(TagBiz tagBiz) { this.tagBiz = tagBiz; } public Favorite getFav() { return fav; } public void setFav(Favorite fav) { this.fav = fav; } public Tag getTag() { return tag; } public void setTag(Tag tag) { this.tag = tag; } public List<Favorite> getFavList() { return favList; } public void setFavList(List<Favorite> favList) { this.favList = favList; } public List<Tag> getTagList() { return tagList; } public void setTagList(List<Tag> tagList) { this.tagList = tagList; } public List<String> getUrlList() { return urlList; } public void setUrlList(List<String> urlList) { this.urlList = urlList; } }
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> <package name="Fav" extends="struts-default" namespace="/"> <action name="toAdd" class="cn.action.FavAction" method="toAdd"> <result name="success">WEB-INF/jsp/fav/add.jsp</result> </action> <action name="doAdd" class="cn.action.FavAction" method="doAdd"> <result name="success">WEB-INF/jsp/fav/list.jsp</result> </action> <action name="toList" class="cn.action.FavAction" method="toList"> <result name="success">WEB-INF/jsp/fav/list.jsp</result> </action> <action name="toCloud" class="cn.action.FavAction" method="toCloud"> <result name="success">WEB-INF/jsp/fav/cloud.jsp</result> </action> </package> </struts>
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"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <head> <title>网站收藏</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <link rel="stylesheet" type="text/css" href="<%=basePath%>/css/styles.css"> <script type="text/javascript" src="<%=basePath%>/js/jquery-1.3.2.js"></script> <script type="text/javascript"> function add() { window .open( 'toAdd.action', '_blank', 'height=350, width=380, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no,left=180,top=200'); } </script> </head> <body> <s:form name="fav" method="post"> <div class="banner"> <img src="images/logo.gif"></img> 网站收藏 </div> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td style="text-align:right;" valign="top"> <!-- 左边Tag列表 --> <div class="left_labels"> <table class="labels_table" cellspacing="0" cellpadding="0" border="0"> <tr> <td><a href="javascript:add();" style="font-weight:bold;">添加书签</a> </td> </tr> <tr> <td><a href="toList.action?type=-1">全部</a></td> </tr> <tr> <td><a href="toList.action?type=0">未分类</a></td> </tr> <s:iterator id="tag" value="tagList"> <tr> <td><a href="toList.action?type=<s:property value='#tag.name'/>"> <s:property value="#tag.name" /> </a></td> </tr> </s:iterator> <tr> <td class="selected_label"><a style="font-weight:bold;" href="toCloud.action">云图</a></td> </tr> </table> </div></td> <td> <!-- 右边fav内容 --> <div class="content_links" id="content"> <s:iterator id="url" value="favList"> <div style="padding:6px 10px;"> <div> <a href="<s:property value="#url.url"/>" style="color:blue;font-size:18px;" target="_blank"><s:property value="#url.label" /> </a> </div> <div style="color:black;font-size:16px;"> <s:property value="#url.desc" /> </div> <div style="color:green;font-size:14px;"> <s:property value="#url.url" /> </div> </div> </s:iterator> </div></td> </tr> </table> <div class="copyright">© 2014 互联网信息技术有限公司</div> </s:form> </body>
效果图:
cloud.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"> <head> <title>网站收藏</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <script type="text/javascript" src="<%=basePath%>/js/jquery-1.3.2.js"></script> <link rel="stylesheet" type="text/css" href="<%=basePath%>/css/styles.css"> <script type="text/javascript"> function add() { window .open( 'toAdd.action', '_blank', 'height=600, width=400, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no'); } </script> </head> <body> <s:form name="fav" method="post"> <div class="banner"> <img src="images/logo.gif"></img> 网站收藏 </div> <table cellspacing="0" cellpadding="0" border="0"> <tr> <td style="text-align:right;" valign="top"> <!-- 左边Tag列表 --> <div class="left_labels"> <table class="labels_table" cellspacing="0" cellpadding="0" border="0"> <tr> <td><a href="#" onclick="add();" style="font-weight:bold;">添加书签</a> </td> </tr> <tr> <td><a href="#" onclick="showTags(-1)">全部</a> </td> </tr> <tr> <td><a href="#" onclick="showTags(0)">未分类</a> </td> </tr> <s:iterator id="tag" value="tagList"> <tr> <td><a href="javascript:showTags('${tag.name}')">${tag.name}</a> </td> </tr> </s:iterator> <tr> <td class="selected_label"><a style="font-weight:bold;" href="toCloud.action">云图</a> </td> </tr> </table> </div></td> <td> <!-- 右边fav内容 --> <div class="content_links" id="content"> <div style="padding:30px;width:450px;font-family:verdana;"> <s:iterator id="tag" value="tagList"> <!-- 根据数量显示不同的class --> <a class="tag<s:property value="#tag.count"/>" href="toList.action?type=<s:property value='#tag.name'/>"> <s:property value="#tag.name" /> </a> </s:iterator> </div> </div></td> </tr> </table> <div class="copyright">© 2014 互联网信息技术有限公司</div> </s:form> </body>
效果图:
add.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"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <head> <title>添加书签</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <link rel="stylesheet" type="text/css" href="<%=basePath%>/css/styles.css"> </head> <body> <s:form name="fav" action="doAdd" method="post"> <div class="banner"> <img src="images/logo.gif"></img> 网站收藏 </div> <table border="0" class="input_table"> <tr> <td colspan="2"><s:textfield name="fav.label" size="40" label="名称" /> </tr> <tr> <td colspan="2"><s:textfield name="fav.url" size="40" label="链接" /> </td> </tr> <tr> <td colspan="2"><font color="green">Tag可以多个,用“,”隔开</font> </td> </tr> <tr> <td colspan="2"><s:textfield label="Tag" name="fav.tags" size="40" /> </td> </tr> <tr> <td colspan="2"><s:textarea label="描述" name="fav.desc" rows="4" cols="39"></s:textarea> </td> </tr> <tr> <td><button onclick="window.close();">取消</button> </td> <td><button onclick="this.form.submit();">提交</button> </td> </tr> </table> </s:form> </body>
效果图:
相关推荐
Struts+srping+Hibernate开发青协志愿服务管理系统 数据库 mysql(关系型数据库) 前台技术 JSP(css,js,...WEB-INF (lib+jsp+*.xml) applicationContext.xml 中心配置文件 web.xml 项目配置文件 项目一些基本配置参数
Struts+srping+Hibernate开发青协志愿服务管理系统 数据库 mysql(关系型数据库) ...WEB-INF (lib+jsp+*.xml) applicationContext.xml 中心配置文件 web.xml 项目配置文件 项目一些基本配置参数 127.0
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 ...
JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的Action等 VO --> bean.java及 bean.hbm.xml配置文件 Service --> Service接口定义类 ...
JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的Action等 VO --> bean.java及 bean.hbm.xml配置文件 Service --> Service接口定义类 ...
JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的Action等 VO --> bean.java及 bean.hbm.xml配置文件 Service --> Service接口定义类 DAO --...
JSP文件--> 具有Struts2.0支持的增、删、改、查页面及自定义查询、自动分页等操作 Action--> 业务Action.java和导出Excel的Action等 VO --> bean.java及 bean.hbm.xml配置文件 Service --> Service接口定义类 ...
SSH2(Spring + Struts2 + Hibernate)是一个流行的Java Web开发框架...struts.xml:Struts2的配置文件,定义Action和Result等。 Action类:处理用户请求和业务逻辑。 JSP页面:展示用户界面。 业务逻辑层(Spring)
目录 ...struts2表单标签 1 1、struts资源文件中文解决...SSH Struts+Spring+Hibernate整合 38 创建WEB工程 39 添加Struts2.1开发支持 39 添加Spring开发支持 39 添加Hibernate支持 40 添加Jar包 42 修改Web.xml文件, 42
3.6.编辑struts.xml,配置请求和页面转发路径 3.7.编辑applicationContext.xml, dao注入sessionFactory,service注入dao,action注入service。实现Spring IoC配置 4 各模块具体实现 4.1 登录模块
(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自带的...
在struts.xml中配置页面跳转关系, 21 在applicationContext.xml中配置类之间的调用关系, 22 通知 23 通知文件MyAdvice,schema方法的通知 23 在applicationContext.xml中配置通知--通知文件logAdvice 25 引用AOP的...
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-...
struts2+hibernate4+spring3的整合 步骤:a. 创建数据库表 userinfo b. 创建web工程,导入支持 c.... d.... jsp --> action -->... e.配置spring 的applicationContext.xml ...配置struts.xml g.编写页面
系统的基本业务流程是: 在表示层中,首先通过JSP页面实现交互界面,负责传送请求(Request)和接收响应(Response),然后Struts根据配置文件(struts-config.xml)将ActionServlet接收到的Request委派给相应的Action...
本资料详细介绍了SSH架构的优缺点,可作为面试资料备用! 常说的好处 开源 常说的坏处 配置文件过大我就不提了 struts 优点: 收集,验证表单数据相比传统servlet简单 优雅的实现可配置的请求转发 ...