The above coding is my struts.xml file.There i used tile configuration and the root for action class
My Action class is given below
i use Dao class to store the data in database.Without using tiles it was work but i include tiles configuration means it will not work
package pack;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class FirstDoaclass implements FirstDoaInterface{
SessionFactory sf=null;
Session ses=null;
Transaction t=null;
@Override
public void save(LoginAction la) {
// TODO Auto-generated method stub
this.sf=new Configuration().configure().buildSessionFactory();
this.ses=sf.openSession();
this.t=ses.beginTransaction();
bank r=new bank();
r.setName(la.getName());
r.setUsername(la.getUsername());
r.setPassword(la.getPassword());
r.setAddress(la.getPassword());
r.setEmail(la.getEmail());
r.setAge(la.getAge());
r.setBranch(la.getBranch());
r.setAccno(la.getAccno());
ses.save(r);
t.commit();
ses.close();
}
}
My Tiles.xml File
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="baselayout" template="/Baselayout.jsp">
<put-attribute name="title" value=""></put-attribute>
<put-attribute name="header" value="/Header.jsp"></put-attribute>
<put-attribute name="menu" value="/Menu.jsp"></put-attribute>
<put-attribute name="body" value=""></put-attribute>
<put-attribute name="footer" value="Footer.jsp"></put-attribute>
</definition>
<definition name="/RegisterForm.tiles" extends="baselayout">
<put-attribute name="title" value="welcome To Our Process"/>
<put-attribute name="body" value="/Login.jsp"/>
</definition>
</tiles-definitions>
My Dao Interface Class
package pack;
public interface FirstDoaInterface {
public void save(LoginAction la);
}
My Pojo class
package pack;
public class bank {
private int Userid;
private String name=null;
private String username=null;
private String password=null;
private String Address=null;
private String email=null;
private int age;
private String Branch=null;
private String Accno=null;
/**
* @return the accno
*/
public String getAccno() {
return Accno;
}
/**
* @param accno the accno to set
*/
public void setAccno(String accno) {
this.Accno = accno;
}
/**
* @param userid the userid to set
*/
/**
* @return the userid
*/
public int getUserid() {
return Userid;
}
public void setUserid(int userid) {
this.Userid = userid;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @param username the username to set
*/
public void setUsername(String username) {
this.username = username;
}
/**
* @return the password
*/
public String getPassword() {
return password;
}
/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return the address
*/
public String getAddress() {
return Address;
}
/**
* @param address the address to set
*/
public void setAddress(String address) {
this.Address = address;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return the age
*/
public int getAge() {
return age;
}
/**
* @param age the age to set
*/
public void setAge(int age) {
this.age = age;
}
/**
* @return the branch
*/
public String getBranch() {
return Branch;
}
/**
* @param branch the branch to set
*/
public void setBranch(String branch) {
this.Branch = branch;
}
}
My Action Class
package pack;
import com.opensymphony.xwork2.ActionSupport;
public class LoginAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 1L;
private int Userid;
private String name;
private String username;
private String password;
private String Address;
private String email;
private int age;
private String Branch;
private String Accno;
/**
* @return the userid
*/
public int getUserid() {
return Userid;
}
/**
* @param userid the userid to set
*/
public void setUserid(int userid) {
this.Userid = userid;
}
/**
* @return the accno
*/
public String getAccno() {
return Accno;
}
/**
* @param accno the accno to set
*/
public void setAccno(String accno) {
this.Accno = accno;
}
/**
* @return the email
*/
public String getEmail() {
return email;
}
/**
* @param email the email to set
*/
public void setEmail(String email) {
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return Address;
}
public void setAddress(String address) {
Address = address;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getBranch() {
return Branch;
}
public void setBranch(String branch) {
Branch = branch;
}
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;
}
public String execute() {
FirstDoaInterface ff=new FirstDoaclass();
ff.save(this);
return SUCCESS;
}
}
My jsp page
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!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">
<title>Registration Form</title>
</head>
<body>
<s:form action="login.action" method="post" validate="true" >
<b><s:textfield name="name" label="Name" />
<s:textfield name="username" label="User Name" />
<s:password name="password" label="Password"> </s:password>
<s:password name="confirmpassword" label="Confirm Password"> </s:password>
<s:textarea name="address" label="Address" />
<s:textfield name="email" label="Email" />
<s:textfield name="age" label="Age" />
<s:combobox list="#{'641042':'coimbatore','650044':'chennai'}" headerKey="-1" headerValue="---Select---" label="Branch" name="branch"></s:combobox>
<s:submit method="execute" label="login"/></b>
</s:form>
</body>
</html>
My baseLayout class
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!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">
<title>BaseLayout</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="2" align="center">
<tr>
<td height="30" colspan="2"><tiles:insertAttribute name="header" />
</td>
</tr>
<tr>
<td height="250"><tiles:insertAttribute name="menu" /></td>
<td width="350"><tiles:insertAttribute name="body" /></td>
</tr>
<tr>
<td height="30" colspan="2"><tiles:insertAttribute name="footer" />
</td>
</tr>
</table>
</body>
</html>
My Success Page
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<!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">
<title>Login</title>
</head>
<body>
<table>
<tr><td>Welcome</td><td> <s:property value="name"></s:property></td></tr>
<tr><td>Your User Name is:</td><TD><s:property value="username"/></TD> </tr>
<tr><td>Your Password is:</td><TD><s:property value="password" /></TD></tr>
<tr><td><a href="#">Click Here.....</a></td></tr>
</table>
</body>
</html>

New Topic/Question
Reply


MultiQuote







|