i am using struts 1.2,Eclipse Platform Version: 3.4.2,mySql 5.0.1,jdk 1.5..
i have a login form(jsp) in which a user logs in,in case he doesnt enter his username and/or password an error is displayed using the <ul> tag and <html:errors> in the jsp. in the from class a vaidate method creates an actionerrors object adds all the errors to it and finally returns it.
the ids are linked in messageresource s.properties and appropriate message is diaplayed.
now i want to change the colour of the feild thats unfilled.. ie the username change its font to red in case it empty rather then a message.
thanks in advance.
code:
index.jsp
Expand|Select|Wrap|Line Numbers
- <%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html"%>
- <%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean"%>
- <%@ taglib uri="/WEB-INF/tlds/struts-logic.tld" prefix="logic"%>
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
- pageEncoding="ISO-8859-1"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
- <meta http-equiv="Pragma" content="no-cache">
- <meta http-equiv="Cache-Control" content="no-cache">
- <title>Welcome Page</title>
- <link href="example.css" rel="stylesheet" type="text/css" />
- </head>
- <body background="nexus.jpg">
- <div id="top">
- <table border="0">
- <tr>
- <td width="250"><img src="car.jpg" /></td>
- <td width="250">
- <img src="title.jpg" />
- </td>
- <td width="250">
- <h2 align="right">
- <logic:notPresent name="loginForm" property="result" scope="session">
- Welcome Please Sign In<br>
- </logic:notPresent>
- <logic:present name="loginForm" property="result" scope="session">
- welcome <bean:write name="loginForm" property="uid" />!!
- <html:link action="/logout">LogOut</html:link>
- <html:link action="/viewinfo">Account Info</html:link>
- </logic:present></h2>
- </td>
- </tr>
- </table>
- <hr width="100%">
- </div>
- <div id="leftnavigation">
- <h3>FEW LINKS</h3>
- <a href="newcar.jsp">New Car</a><br>
- <a href="oldcar.jsp">Old Car</a><br>
- <a href="Search.jsp">Search</a></div>
- <div id="content">
- <h1>Welcome to the car portal</h1>
- <p>This is the place where you can check out all the latest cars. <br>
- Not only this,you can also add your old cars for sale.<br>
- With our huge member base we are sure to get you a deal you cannot refuse. <br>
- <u>Register today to see the available cars at most affordable prices</u>.</p>
- <h2>New Launches</h2>
- <img src="car1.jpg" /></div>
- <div id="rightnavigation">
- <html:errors />
- <html:form action="/login">
- <logic:present name="loginForm" property="flag" scope="session">
- <font size="2" color="red">UserID/Password Does not exist.<br> New Users please register</font>
- </logic:present>
- <logic:notPresent name="loginForm" property="result" scope="session">
- <h2>LOGIN HERE!!</h2>
- <p>Enter your user id and password to log in</p>
- USER NAME<font size="-1" color="red">*</font> <html:text property="uid" />
- <br>
- PASSWORD<font size="-1" color="red">*</font> <html:password property="psswd" />
- <br>
- <html:submit value="LOG IN" />
- <br>
- <br>
- <html:link forward="nregister">Register Here!!</html:link>
- </logic:notPresent>
- </html:form>
- </div>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- package form;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.struts.action.ActionErrors;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.action.ActionMessage;
- public class LoginForm extends ActionForm
- {
- String Uid;
- String Psswd;
- String result;
- String flag;
- public String getFlag() {
- return flag;
- }
- public void setFlag(String flag) {
- this.flag = flag;
- }
- public String getResult() {
- return result;
- }
- public void setResult(String result) {
- this.result = result;
- }
- public String getUid() {
- return Uid;
- }
- public void setUid(String uid) {
- Uid = uid;
- }
- public String getPsswd() {
- return Psswd;
- }
- public void setPsswd(String psswd) {
- Psswd = psswd;
- }
- public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
- {
- ActionErrors actionErrors= new ActionErrors();
- if(getUid()=="")
- {
- actionErrors.add("Username",new ActionMessage("uid.required"));
- }
- if(getPsswd()=="")
- {
- actionErrors.add("Password",new ActionMessage("psswd.required"));
- }
- return actionErrors;
- }
- public String test(String result)
- { String act;
- if((getUid()=="") || (getPsswd()==""))
- {
- act=null;
- }
- else
- {
- act="true";
- }
- return act;}
- }
Expand|Select|Wrap|Line Numbers
- # -- Standard errors --
- errors.header=<UL>
- errors.prefix=<LI><B><FONT COLOR="RED">
- errors.suffix=</FONT></B></LI>
- errors.footer=</UL>
- # -- Custom validation messages --
- uid.required=Username Required.
- uid.short=Username is too short.
- psswd.required=Password Required.
- psswd.short=Password is too short.
- rpsswd.required=Re Enter the password same as password.
- fname.required=First Name Required.
- lname.required=Last Name Required.
- email.required=Email Address Required.
- email.invalid=Invalid Email Address.
- email.incorrect=Incorrect Format for an Email Id.
- value.match=Username and password are same.
- value.notmatch=Password and retyped password don't match.
- digit.incorrect=Zip,Contact no and Date of birth must have only digits.