天天看點

關于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%>" target="_blank" rel="external nofollow" >

		<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" target="_blank" rel="external nofollow" >
	-->
		<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>