我的 InternalResourceViewResolver 无法正常工作

My InternalResourceViewResolver not working properly

我正在尝试使用带注释的 Spring 框架开发一个小应用程序,但我真的无法识别我犯了什么错误 InternalResourceViewResolver class 没有处理来自的请求.jsp 页。这是我的项目详情。

index.jsp

<jsp:forward page="login.form" ></jsp:forward>

spring-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <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'

我不知道,如果我理解正确的话,但是你加载 .jsp 页时出错了?

<!-- View Resolver -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix"   value="/"></property>
<property name="suffix"   value=".jsp"></property>
</bean>

您好像对 spring 说,要在直接目录(可能是 webapp)中查找 .jsp 页面。您将 .jsp 文件保存在哪里?您应该提供包含 .jsp 文件的确切文件夹,例如 <beans:property name="prefix" value="/WEB-INF/views/" />