欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

SSH action+struts.xml+jsp

程序员文章站 2022-06-09 17:18:53
...

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">&copy; 2014 互联网信息技术有限公司</div>
	</s:form>
</body>

 

效果图:
SSH action+struts.xml+jsp
            
    
    博客分类: item08 收藏
 

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>&nbsp;
							</s:iterator>
						</div>
					</div></td>
			</tr>
		</table>
		<div class="copyright">&copy; 2014 互联网信息技术有限公司</div>
	</s:form>
</body>

 

效果图:
SSH action+struts.xml+jsp
            
    
    博客分类: item08 收藏
 

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>

 

效果图:
SSH action+struts.xml+jsp
            
    
    博客分类: item08 收藏
 

 

 

  • SSH action+struts.xml+jsp
            
    
    博客分类: item08 收藏
  • 大小: 57.4 KB
  • SSH action+struts.xml+jsp
            
    
    博客分类: item08 收藏
  • 大小: 43.9 KB
  • SSH action+struts.xml+jsp
            
    
    博客分类: item08 收藏
  • 大小: 67.4 KB