2017-01-28 12 views
-1

基本的なSpring MVCログインページ機能が動作しません。 データベース接続が正常に動作しています。 正しいユーザー名とパスワードを入力すると、else条件になります。 ifループ機能が動作しません。親切にいくつかのいずれかが助けてくれ基本的なSpring MVCログインページ機能が動作しない

LoginController

package com.programcreek.helloworld.controller; 

import java.sql.SQLException; 
import org.springframework.context.ApplicationContext; 
import org.springframework.context.support.ClassPathXmlApplicationContext; 
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 { 

    @RequestMapping("/login") 
    public ModelAndView viewLogin() 
    { 
     ModelAndView mv = new ModelAndView("login"); 
     return mv; 
    } 


    @RequestMapping(value ="/submitlogin", method= RequestMethod.POST) 
    public ModelAndView submituserLogin(@RequestParam("userName")String userName, @RequestParam("password")String password) throws SQLException 
    { 

     ApplicationContext context = 
       new ClassPathXmlApplicationContext("Beans.xml"); 

      LicenseManagementDaoImp LicenseManagementDaoImp = 
      (LicenseManagementDaoImp)context.getBean("LicenseManagementDaoImp"); 

      UserAccountController formInfo = new UserAccountController(userName,password);     
      UserAccountController userAcc = LicenseManagementDaoImp.loginInfo(userName); 

      if(formInfo.getUserName() == userAcc.getUserName() && formInfo.getPassword() == userAcc.getPassword()) 
      { 
       ModelAndView mv = new ModelAndView("loginsuccess"); 
       mv.addObject("headermsg","You have successfully logged in"); 
       mv.addObject("msg1", userAcc.getUserName()); 
       mv.addObject("msg2", userAcc.getPassword()); 
       return mv;   
      } 

      else 
      { 
       ModelAndView mv = new ModelAndView("login"); 
       mv.addObject("msg1", "Please enter a Valid Username or Password"); 
       return mv; 

      } 


      } 

    } 

UserAccountController

package com.programcreek.helloworld.controller; 

public class UserAccountController 

{ 
    private String userName; 
    private String password; 

    public UserAccountController() 
    { 

    } 

    public UserAccountController(String userName, String password) 
    { 
    super(); 
    this.userName = userName; 
    this.password = password; 
    } 

public String getUserName() { 
    return userName; 
} 

public void setUserName(String userName) { 
    this.userName = userName; 
} 

public String getPassword() { 
    return password; 
} 

public void setPassword(String password) { 
    this.password = password; 
} 


} 

LicenseManagementDaoImp

package com.programcreek.helloworld.controller; 

import java.sql.SQLException; 
import javax.sql.DataSource; 
import org.springframework.dao.EmptyResultDataAccessException; 
import org.springframework.jdbc.core.JdbcTemplate; 

public class LicenseManagementDaoImp 
{ 
    private DataSource dataSource; 
    private JdbcTemplate jdbcTemplateObject; 

    public void setDataSource(DataSource dataSource) 
    { 
     this.dataSource = dataSource; 
     this.jdbcTemplateObject = new JdbcTemplate(dataSource); 
    } 


    public UserAccountController loginInfo(String userName) throws SQLException 
    { 
     try 
     { 
     String SQL = "Select strusername, strpassword from user where strusername = ? "; 
     UserAccountController userAcc = jdbcTemplateObject.queryForObject(SQL, new LicenseManagementMapper(), userName);   
     return userAcc; 

     } 
     catch(EmptyResultDataAccessException e) 
     { 
      return new UserAccountController();  
     } 
    } 



} 
ここで注意すべき

LicenseManagementMapper

package com.programcreek.helloworld.controller; 

import java.sql.ResultSet; 
import java.sql.SQLException; 
import org.springframework.jdbc.core.RowMapper; 



public class LicenseManagementMapper implements RowMapper<UserAccountController> 
{ 
    public UserAccountController mapRow(ResultSet rs, int rowNum) throws SQLException 
    { 
     UserAccountController userAcc = new UserAccountController(); 
     userAcc.setUserName(rs.getString("strusername")); 
     userAcc.setPassword(rs.getString("strpassword")); 
     return userAcc;     
     } 
} 

答えて

0

いくつかのこと:

はsubmitUserLogin全体春のコンテキストを作成しないでください。

==を使用している文字列を 'equals'と比較することは正しくありません。

関連する問題