学习使用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.1.8.jar,Struts2升级以后把Ajax和一些控件功能单独提取出来了,且放在了struts2-dojo-plugin-2.1.8.jar里。像我用的就是struts2.1.8,所以要在项目lib中加入struts2-dojo-plugin-2.1.8.jar这个包后, 页面应该改成: <%@ taglib prefix=”s” uri=”/struts-tags”%> <%@ taglib prefix=”sd” uri=”/struts-dojo-tags”%> <head> <s:head theme=”xhtml”/> <sd:parseContent=”true”/></head>….. <sd:datetimepicker label=”生日” name=”birthday”></sd:datetimepicker>而时间空间应该使用sd标签
原文地址: http://download.csdn.net/detail/zzb13425138525/3206869