struts2中head标签的使用
www.diybl.com 时间 : 2010-08-03 作者:网络 编辑:huyang629 点击: [ 评论 ]
在Struts2中的JSP文件使用<s:head/>可以得到一些加入js的效果
login.jsp
<%@ page language="Java" contentType="text/html; charset=GBK"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>登录页面</title>
<s:head/>
</head>
<body>
<s:form action="Login.action" method="post">
<s:textfield name="name" label="用户名"/>
<s:password name="password" label="密码"/>
<s:submit value="登录"/>
</s:form>
</body>
</html>
1、输入:http://localhost:8080/strutsdemo/login.jsp

2、得到:
没有加<head/>时候得到

加<s:head/>后,浏览器源文件代码
1<html>
2<head>
3<title>��¼ҳ��</title>
4<link rel="stylesheet" href="/strutsdemo/struts/xhtml/styles.css" type="text/css"/>
5<script type="text/JavaScript">
6 // Dojo configuration
7 djConfig = {
8 baseRelativePath: "/strutsdemo/struts/dojo",
9 isDebug: false,
10 bindEncoding: "UTF-8",
11 debugAtAllCosts: true // not needed, but allows the Venkman debugger to work with the includes
12 };
13</script>
14<script type="text/javascript"
15 src="/strutsdemo/struts/dojo/dojo.js"></script>
16<script type="text/javascript"
17 src="/strutsdemo/struts/simple/dojoRequire.js"></script>
18
19</head>
20<body>
21
22<form id="Login" onsubmit="return true;" action="Login.action" method="post">
23<table class="wwFormTable">
24 <tr>
25 <td class="tdLabel"><label for="Login_name" class="label">�û���:</label></td>
26 <td
27><input type="text" name="name" value="" id="Login_name"/>
28</td>
29</tr>
30
31 <tr>
32 <td class="tdLabel"><label for="Login_password" class="label">����:</label></td>
33 <td
34><input type="password" name="password" id="Login_password"/>
35</td>
36</tr>
37
38 <tr>
39 <td colspan="2"><div align="right"><input type="submit" id="Login_0" value="��¼"/>
40</div></td>
41</tr>
42
43</table></form>
44
45</body>
46</html>
47
3、由于加入了validation校验框架,在没有输入用户名跟密码时候,按登录产生一下界面

浏览器的源代码:
1<html>
2<head>
3<title>登录页面</title>
4<link rel="stylesheet" href="/Strutsdemo/struts/xhtml/styles.css" type="text/css"/>
5<script type="text/JavaScript">
6 // Dojo configuration
7 djConfig = {
8 baseRelativePath: "/strutsdemo/struts/dojo",
9 isDebug: false,
10 bindEncoding: "UTF-8",
11 debugAtAllCosts: true // not needed, but allows the Venkman debugger to work with the includes
12 };
13</script>
14<script type="text/Javascript"
15 src="/strutsdemo/struts/dojo/dojo.js"></script>
16<script type="text/javascript"
17 src="/strutsdemo/struts/simple/dojoRequire.js"></script>
18
19</head>
20<body>
21
22<form id="Login" onsubmit="return true;" action="Login.action" method="post">
23<table class="wwFormTable">
24 <tr errorFor="Login_name">
25 <td align="center" valign="top" colspan="2"><span class="errorMessage">用户名必填</span></td>
26</tr>
27<tr>
28 <td class="tdLabel"><label for="Login_name" class="errorLabel">用户名:</label></td>
29 <td
30><input type="text" name="name" value="" id="Login_name"/>
31</td>
32</tr>
33
34 <tr errorFor="Login_password">
35 <td align="center" valign="top" colspan="2"><span class="errorMessage">密码必填</span></td>
36</tr>
37<tr>
38 <td class="tdLabel"><label for="Login_password" class="errorLabel">密码:</label></td>
39 <td
40><input type="password" name="password" id="Login_password"/>
41</td>
42</tr>
43
44 <tr>
45 <td colspan="2"><div align="right"><input type="submit" id="Login_0" value="登录"/>
46</div></td>
47</tr>
48
49
50</table></form>
51
52
53
54
55</body>
56</html>