I am trying develope a small application using Spring Framework with Annotation but i really not able to recognized what i made mistake that InternalResourceViewResolver
class not handling request that is coming from .jsp
page. here is my project details.
index.jsp
<jsp:forward page="login.form" ></jsp:forward>
spring-servlet.xml
<beans xmlns="http://ift.tt/GArMu6"
xmlns:context="http://ift.tt/GArMu7"
xmlns:xsi="http://ift.tt/ra1lAU"
xmlns:tx="http://ift.tt/OGfeU2"
xmlns:mvc="http://ift.tt/1bHqwjR"
xsi:schemaLocation="http://ift.tt/GArMu6
http://ift.tt/1jdM0fG
http://ift.tt/OGfeU2 http://ift.tt/18tm2Tg
http://ift.tt/GArMu7
http://ift.tt/1ldEMZY">
<context:component-scan base-package="com.nody.spring.controller"></context:component-scan>
<context:annotation-config></context:annotation-config>
<!-- Handler Mapping -->
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMappping"></bean>
<!-- View Resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean id="jt" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="ds"></property>
</bean>
<bean id="ds" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:xe"></property>
<property name="username" value="scott"></property>
<property name="password" value="tiger"></property>
</bean>
</beans>
LoginController.java
package com.nody.spring.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class LoginController {
private LoginService loginService;
@Autowired
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
@RequestMapping(value="/login.form", method=RequestMethod.GET)
public ModelAndView getLoginPage()
{
return new ModelAndView("login");
}
@RequestMapping(value="check", method=RequestMethod.POST)
public ModelAndView checkLogin(@RequestParam("uname")String s1,@RequestParam("pword")String s2)
{
boolean b=loginService.check(s1,s2);
if(b)
return new ModelAndView("success");
else
return new ModelAndView("failure");
}
}
LoginService.java
package com.nody.spring.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
@Repository
public class LoginService {
private JdbcTemplate jt;
@Autowired
@Qualifier("jt")
public void setJt(JdbcTemplate jt)
{
this.jt=jt;
}
public boolean check(String s1,String s2)
{
@SuppressWarnings("deprecation")
int i=jt.queryForInt("select count(*) from users where uname=? and pword=?",s1,s2);
if(i==1)
return true;
else
return false;
}
}
List of jars
aspectj-weaver.jar
atomikos-transactions-api.jar
atomikos-transactions-jta.jar
atomikos-util.jar
commons-logging-api-1.1.1.jar
javax.transaction-3.1.jar
jta.jar
mysql-connector-java-5.1.6.jar
ojdbc14.jar
spring-aop-4.1.4.RELEASE.jar
spring-beans-4.1.4.RELEASE.jar
spring-context-4.1.4.RELEASE.jar
spring-context-support-4.1.4.RELEASE.jar
spring-core-4.1.4.RELEASE.jar
spring-expression-4.1.4.RELEASE.jar
spring-jdbc-4.1.4.RELEASE.jar
spring-tx-4.1.4.RELEASE.jar
transactions-3.7.0.jar
transactions-jdbc-3.7.0.jar
aopalliance.jar
aspectjrt-1.8.5.jar
failure.jsp
<form action="check.form" method="POST">
Username:<input type=text name="uname"><br>
Password<input type=password name="pword"><br>
<input type=submit value="SUBMIT">
</form>
success.jsp
<h1>Login Success !!!</h1>
failure.jsp
<h1>Login Success !!!</h1>
and Oracle Table name is 'users' with 2 columns 'uname' and 'pword'
Aucun commentaire:
Enregistrer un commentaire