struts2中用ajax标签出错。。一使用<s:head theme="ajax"/>就报错或者标签的时间控件显示不出来

来源:互联网 发布:淘宝买二手电脑经历 编辑:程序博客网 时间:2024/06/03 20:23

http://fightingit.blog.163.com/blog/static/201246211201252210105472/


学习使用struts2的ajax时,看书说要引入<s:head theme="ajax"/>,但引入后就一直报错

在jsp页面的<head></head>之间插入<s:head theme="ajax"/>这句话,打开页面弹个对话框提示站点无法访问,如果把<s:head theme="ajax"/>这句取消了,才能打开页面,但这页面也失去ajax功能了

这主要是strut2版本的问题,不是你代码的问题

页面部分关键代码粘贴在下面了。。
<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">
-->
  <s:head theme="ajax"/> <!--加了这句就打不开页面-->
  </head>
  
  <body>
    <s:form action="register" theme="ajax" validate="true">
     <s:textfield label="用户名" name="username"></s:textfield>
     <s:password label="密码" name="password"></s:password>
     <s:password label="重新输入密码" name="repassword"></s:password>
     <s:textfield label="年龄" name="age"></s:textfield>
     <s:datetimepicker label="生日" name="birthday"></s:datetimepicker>加了这句后,时间控件同样显示不出来
     <s:submit value="发布"></s:submit>
    </s:form>
    <s:property value="result"/>
  </body>
</html>

 

如果你的Struts版本是2.1.6或以上的,那就要加struts2-dojo-plugin-2.2.3.1.jar,Struts2升级以后把Ajax和一些控件功能单独提取出来了,且放在了struts2-dojo-plugin-2.2.3.1.jar里。像我用的就是struts2.2.3.1,所以要在项目lib中加入struts2-dojo-plugin-2.2.3.1.jar这个包后,  页面应该改成: 
 <%@ taglib prefix="s" uri="/struts-tags"%> 
 <%@ taglib prefix="sd" uri="/struts-dojo-tags"%>  
<head>  
<sd:head parseContent="true"/>
</head>
.....
 <sd:datetimepicker displayFormat="yyyy-MM-dd" label="生日" name="birthday"></sd:datetimepicker>而时间空间应该使用sd标签

原创粉丝点击