jsp - why did my text box value not getting in action Class using struts? i am getting password field's value but not of text field -
this action class, hv defined struts.xml, problem that, getting textbox username value null, other inputs returning value. adding user.java class, struts actionclass.
public class userlogin extends actionsupport { user user = new user(); public string getaccess() { system.out.println(user.getpassword()+"and"+user.getusername()); // output: xyz , null if (user.getpassword().equals("pass")){ system.out.println(user.getusername()); return "success"; } else{ return "input"; } } public user getmodel() { return user; } }
and jsp page is:
<form action="login"> username:<input type="text" name="username"/> password:<input type="password" name="password"/> <input type="submit" value="login"/> </form>
user.java
public user { private string username; private string password; public string getusername(){ return username; } public void setusername(string username) { this.username = username; } public string getpassword(){ return password; } public void setpassword(string password) { this.password= password; } }
use jsp taglib
taking user input use following jsp form put code in login.jsp
file.
<%@ page contenttype="text/html; charset=utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <html> <head> <title>login</title> </head> <body> <s:form action="login" method="get"> <s:textfield name="username" key="username" size="20" /> <s:password name="password" key="password" size="20" /> <s:submit method="getaccess" align="center"/> </s:form> </body> </html>
if following line
<%@ taglib prefix="s" uri="/struts-tags"%>
give error download jsp tag lib jar , put in lib folder.
Comments
Post a Comment