This is my code I had written a logic to fetch the username
and password
from and database and after login the login time and logout time should enter into the database the time should be taken from the system
action class:
public class Login {
private String username;
private String password;
private String login_time;
private String logout_time;
private String status;
private String late;
//getters and setters
@SuppressWarnings("unused")
public String execute(ServletRequest req) throws Exception,SQLException{
int i=0;
try{
SessionUtils su = new SessionUtils();
HttpSession session =((Request) req).getSession();
String hql="select * from login where username='"+username+"'and
password='"+password+"'";
Query query1=((SessionUtils) session).createQuery(hql);
query1.setParameter(1,getUsername());
query1.setParameter(2,getPassword());
int result = query1.executeUpdate();
while(i!=0)
{
RequestDispatcher rd
=req.getRequestDispatcher("DailyInOut.jsp");
return hql;
}
} catch (Exception e)
{
return late;
}
return status;
}
public String chandu(ServletRequest req,ServletResponse res) throws
Exception,SQLException{
int j=0;
try
{
java.util.Date myDate = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss");
String strDates1 = formatter.format(myDate);
@SuppressWarnings("unused")
SessionUtils su = new SessionUtils();
String hql="update attendance where date='"+strDates1+"' name='"+username+"'
login='"+login_time+"' logout='"+logout_time+"' status='"+status+"'
late='"+late+"'";
HttpSession session =((Request) req).getSession();
Query query2=((SessionUtils) session).createQuery(hql);
session.setAttribute("date", strDates1);
session.setAttribute("login_time",login_time);
session.setAttribute("logout_time",logout_time);
session.setAttribute("status",status);
session.setAttribute("late",late);
@SuppressWarnings("unused")
int result = query2.executeUpdate();
System.out.println(" update row updated");
if(j!=0)
{
System.out.println("success1");
return "success";
}
}
catch(Exception e)
{
e.getMessage();
}
System.out.println("failure page");
return "failure";
}
}
struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package namespace="/" name="packageOne" extends="struts-default">
<action name="login" class="com.tribro.chandu.Login" method="post">
<result name="success">DailyInOut.jsp</result>
</action>
</package>
</struts>
logina.jsp
<html>
<head>
<title>Home Page</title>
</head>
<body bgcolor="cyan" text="magenta">
<form action="login" method="execute">
<img src="WebContent/Images/java.jpg" height="80"/>
<pre><marquee behavior="scroll" direction="right"><font size="4">Welcome to TRIBRO
Limited</font></marquee><br/></pre>
<table>
<tr>
<td>
<div>
<img src="WebContent/Images/banner.png" height="300" width="900"></img>
</div>
</td>
<td>
<div>
<table>
<tr>
<td colspan="2" style="text-align:center;">
<h4>Login Form</h4>
</td>
</tr>
<tr>
<td>
<h4>Username :</h4>
</td>
<td>
<h4><input type="text" name="Username"/></h4>
</td>
</tr>
<tr>
<td>
<h4>password:</h4>
</td>
<td>
<h4><input type="password" name="password"/></h4>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
<input type="submit" value="Login"/>
</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
But I am getting an error as
java.lang.NoSuchMethodException: com.tribro.chandu.Login.post()