Dear All,
I am a beginner of using spring concept. I
am writing a small Login program using Struts and spring.I am just hard coded the
string if the login id and Password is matching then it will go to welcome.jsp.It is working fine.
With this logic in BusinessDelegate.java it is working properly.
public String validateUser(String userName, String password) {
String data=null;
if(userName.equals("admin") && password.equals("123")) {
return "success";
}
return "failure";
}
I am calling validateUser() in LoginAction.java file.
target = businessDelegate.validateUser(loginForm.getUserName(),loginForm.getPassword());
But I want it should check with database level and if the login id and password matching then it will go to welcome page.
How can I write the syntax in BusinessDelegate.java so that it should work.
Like
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}
public String validateUser(String userName, String password) {
jdbcTemplate.queryForList("select login_name,password from ABC_USER where login_name='"+userName+"',password='"+password+"'");
if(rs.next())
{
return “success’;
}
Else
return “failure”;
}
[b]ApplicationContext.xml
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<!-- <property name="driverClassName" value="com.mysql.jdbc.Driver"/>-->
<!-- <property name="url" value="jdbc:mysql://192.168.10.75:3306/komal"/>-->
<property name="driverClassName" value="com.jnetdirect.jsql.JSQLDriver"/>
<property name="url" value="jdbc:JSQLConnect://192.188.48.28/database=ABC_TEST"/>
<property name="username" value="test"/>
<property name="password" value="test"/>
</bean>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler">
<property name="nativeJdbcExtractor" ref="nativeJdbcExtractor"/>
</bean>
<bean id="nativeJdbcExtractor"
class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor"/>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"/>
</bean>
[b]
Please suggest/rectify my code how it should work with checking the value in database level and if successful login then goto welcome page.
LoginForm.java
LoginAction.java
}
BusinessDelegate.java
ApplicationContext.xml
Web.xml
Struts-config.xml
Please suggest me the syntax of code how my BusinessDelegate.java and ApplicationContext.xml conncet with database and checking the userid and password.
Thanks in advance.
Regards,
Sumanta Panda