下载struts2-dojo-plugin-2.2.3.1.jar,放到/WEB-INF/lib里
在jsp中引入tag
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%@ taglib prefix="s" uri="/struts-tags"%>
- <%@ taglib prefix="sx" uri="/struts-dojo-tags"%>
在<head></head>中加入<sx:head />,<SX:HEAD/>的作用是自动导入struts2 dojo的js和css
- <head>
- <title>测试</title>
- <sx:head />
- </head>
使用datetimepicker标签
- <body>
- <sx:datetimepicker label="时间" name="time" displayFormat="yyyy-MM-dd" value="%{2011-01-01}" />
- </body>
加入按照之前的步骤,仍然无法显示,我刚才遇到的情况就是如此,chrome查看页面源码发现下面的代码都已经生成,但是直接打开/test/struts/ajax/dojoRequire.js 发现资源不存在
- <script language="JavaScript" type="text/javascript">
- // Dojo configuration
- djConfig = {
- isDebug: false,
- bindEncoding: "UTF-8"
- ,baseRelativePath: "/test/struts/dojo/"
- ,baseScriptUri: "/test/struts/dojo/"
- ,parseWidgets : false
- };
- </script>
- <script language="JavaScript" type="text/javascript" src="/test/struts/dojo/struts_dojo.js"></script>
- <textarea id="dojo.widget.RichText.savedContent" style="display:none;position:absolute;top:-100px;left:-100px;height:3px;width:3px;overflow:hidden;"></textarea>
- <script language="JavaScript" type="text/javascript" src="/test/struts/ajax/dojoRequire.js"></script>
- <link rel="stylesheet" href="/test/struts/xhtml/styles.css" type="text/css">
- <script language="JavaScript" src="/test/struts/utils.js" type="text/javascript"></script>
- 。。。
遇到这种情况的时候,请检查web.xml的struts配置,假如struts filter的mapping不是对所有url过滤
那么请加入/struts/*,问题解决
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>
- org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
- </filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>*.action</url-pattern>
- <dispatcher>REQUEST</dispatcher>
- <dispatcher>FORWARD</dispatcher>
- </filter-mapping>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/struts/*</url-pattern>
- </filter-mapping>