struts2 控制 umeditor

上面讲了 struts2  下面讲解umeditor

1:umeditor 下载地址  http://ueditor.baidu.com/website/download.html#mini 

2:下载后直接放在webroot下了,目录


下载后 umeditor 下的jsp 文件,里面两个jar文件加载一下,struts2jar文件也加载进去

3:加载后 index.jsp 文件 我贴出来

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
	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>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link href="umeditor/themes/default/css/umeditor.css" type="text/css"
	rel="stylesheet">

<script type="text/javascript" src="umeditor/third-party/jquery.min.js"></script>
<script type="text/javascript" charset="gbk" src="umeditor/umeditor.config.js"></script>
<script type="text/javascript" charset="gbk" src="umeditor/umeditor.min.js"></script>
<script type="text/javascript" src="umeditor/lang/zh-cn/zh-cn.js"></script>


</head>

<body>
	<form action="pub" method="post">
		<br> 类别: <input type="text" name="category" /><br />
			 标题: <input type="text" name="title" />   <br />
			<script type="text/plain" id="myEditor"    name="content" style="width:1000px;height:240px;">
   			 	<p>这里我可以写一些输入提示</p>
			</script>
		<br>
		<script type="text/javascript">
			//实例化编辑器
			var um = UM.getEditor('myEditor');
		</script>
			<input type="submit" value="提交" />
		</form>
</body>
</html>

用户运行下 看能否有如下界面 


代码:http://download.csdn.net/detail/u011850863/8490089

用户下载后可使用(一些代码就不贴出来了,直接下载查看吧)

重点,web.xml 配置,因为使用 struts2.xml 会把图片上传给过滤掉,所以要自己写一个过滤器

package filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;

public class MyStrutsFilter extends StrutsPrepareAndExecuteFilter {
	public void doFilter(ServletRequest req, ServletResponse res,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		String url = request.getRequestURI();
		if ("/webTest/umeditor/jsp/imageUp.jsp".equals(url)
				|| "/webTest/umeditor/jsp/fileUp.jsp".equals(url)) {
			// System.out.println("使用自定义的过滤器");
			chain.doFilter(req, res);
		} else {
			// System.out.println("使用默认的过滤器");
			super.doFilter(req, res, chain);
		}
		
		
	}

}
web.xml 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
	
	<filter>
		<filter-name>struts2</filter-name>
		<filter-class>filter.MyStrutsFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>struts2</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>


	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
	</welcome-file-list>
	
</web-app>

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
	<constant name="struts.action.excludePattern" value="/resource/.*" />
	<package name="ue" extends="struts-default">
		<action name="pub" class="action.PublishAction"
			method="execute">
			<result>/show.jsp</result>
			<result name="input">/index.jsp</result>
			<!-- <result name="success">/editorUpdate.jsp</result> -->
		</action>
	</package>
</struts>



因为水品原因,写的错误的地方 希望大家指出,麻烦大家了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值