关于struts-2.2.1版本datetimepicker标签

 

 

今天在使用Struts2标签库的时候出现这个问题。谷歌后总算解决了,现在把方法说下:

 

严重: Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /date.jsp(31,3) No tag "datetimepicker" defined in tag library imported with prefix "s"

 原因:struts2.2.1 把struts2.0中的和ajax相关的都移动到了dojo中了 

 

 

 

如果想使用<s:datetimepicker>标签,须导入struts2-dojo-plugin-2.2.1.jar

 

 

解决方法(三步走): 

1、将struts2-dojo-plugin-2.2.1.jar拷贝到/web-inf/lib下
2、在jsp文件中加入
<%@ 
 prefix="sx" taglib uri="/struts-dojo-tags"%><sx:head/>

3、代码<s:form>

       <sx:datetimepicker name="birth" label="出生日期" value="today">    </sx:datetimepicker>
</s:form>

 

这样我们问题就解决了,但是新的问题又出来啦,日期显示的时候月份从一月到八月都可以正常显示,而到九月,十月就乱码,这是一个bug,但是还是很容易解决的!

解决办法:
1  ,这个方法可以解决乱码,但是 月份 都变成 1,2,3.... 了

          在 <sx:head /> 中加入:extraLocales="UTF-8
          在 <sx:datetimepicker .../> 中加入:language="UTF-8

最后代码就是:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="/struts-dojo-tags" prefix="sx"%>
<%
	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 'date.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">
	-->
		<sx:head extraLocales="UTF-8" />
	</head>

	<body>
		<s:form>
			<sx:datetimepicker name="birth" label="出生日期" value="today"
				language="UTF-8"></sx:datetimepicker>
		</s:form>
		<br>
	</body>
</html>
 

 


 

你可能感兴趣的:(jsp,Ajax,struts,css,dojo)