我正在使用 struts2 开发网页。我想用红色边框突出显示我的用户 ID/密码文本字段,并在用户名/密码错误的情况下显示错误消息
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>Stock Portfolio Management</title>
</head>
<FONT COLOR=black><marquee BEHAVIOR=ALTERNATE><h1 ALIGN="center">STOCK PORTFOLIO</h1></marquee></FONT>
<style type="text/css">
body
{
/* background: url(./image/9.jpg) no-repeat fixed; */
/* -webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover; */
postion:fixed
}
img
{
position:fixed;
bottom: 20%;
left: 20%;
margin-top: -50px;
margin-left: -100px;
}
#login
{
position:fixed;
top: 20%;
left: 50%;
margin-top: -50px;
margin-left: -100px;
}
.errors {
background-color:#FFCCCC;
border:1px solid #CC0000;
width:350px;
margin-bottom:2px;
position:relative;
left:0pt;
bottom:10pt;
}
.errors li{
list-style: none;
}
</style>
<body>
<img src="image/9.jpg" height="250" width="300">
<s:form id="login" action="authenticate" method="post">
<s:textfield name="userid" key="User Id" size="25" />
<s:password name="password" label="Password" size="25" />
<s:if test="hasActionErrors()">
<div class="errors">
<s:actionerror/>
</div>
</s:if>
<s:submit method="CheckUser" value="Login" align="center" /> <s:reset value="Reset" align="center" />
<a href="<s:url action="moveregister" method="execute"/>">New User?</a>
 
<a href="<s:url action="forgotpassword" method="forgot"/>">Forgot Password?</a>
</s:form>
</body>
</html>
这就是我在行动课上的内容:
addActionError(getText("User Id which you provided doesnt exists"));
return "error";
如您所见,我正在.errors
使用上面的 CSS 捕获错误并在屏幕上显示并对其进行格式化。
但是我想突出显示带有红色边框的错误userID
字段,如果那是错误或密码字段,如果那是错误。我尝试了谷歌搜索,发现了很多东西,比如编辑你的模板class/<s:fielderror>
等,但无法生成。