Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What should be mentioned in the action property of a form tag in jsp?
What should @RequestMapping corresponds to?

This is the example i am trying -

Home.jsp

XML
<form:form method="get" action = "login">
    <table>
        <tr><td></td><td><input type = "submit" value = "Login"/></td></tr>
    </table>
</form:form>


LoginController.java

@Controller
public class LoginController {
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView validateLogin()
{
String lsQuery = "select count(*) from UserAuth where userid = 'anirba' and password = 'Lahiri0ni'";
Connection con1; PreparedStatement ps;ResultSet rs;
Map<string,string> model = new HashMap<string,string>();
ModelAndView lObjMV = new ModelAndView();
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con1 = DriverManager.getConnection("Jdbc:mysql://localhost/SpringApp", "root", "lahiri");
ps = con1.prepareStatement(lsQuery); rs = ps.executeQuery();
if(rs.next())
{
if(rs.getInt(0) > 0)
{
lObjMV.setViewName("successLog");
//lsViewName = "successLog";
}
else
{
lObjMV.setViewName("failureLog");
//lsViewName = "failureLog";
}
}
lObjMV.addObject(model);
}
catch(Exception lObjS) {}
return lObjMV;
//return lsViewName;
}
}

and two simple jsp pages Namely successLog.jsp and failureLog.jsp for success and failure.

There is no Login.jsp.

When executed its asking for one.
As i know, one gives the request relative url to @RequestMapping of a Controller function. Controller then forwards it to the required view.

Please correct me where am i going wrong.
Thanks in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900