0

i am new to java. I was trying to create a login module.

I have this in a package.. Now I want to call this login() method from jsp file how can I do that using (or not using) userController object.

package com.lagan.controller;
import java.util.List;

import com.lagan.dao.userDao;
import com.lagan.dto.loginDto;
import com.lagan.dto.userDto;

public class userController {
    public List<loginDto> login() {
        userDao dao=new userDao();
        return dao.login();
    }   
}
  • ok....... but in loginVerify.jsp if I had to call create() [in UserController.java], i could have done uC.create() ... Similarly what can i do to call list login(){} ? That is my problem. coz uC.login() is not valid.. –  Oct 13 '19 at 08:24

2 Answers2

0

In your JSP page you need to have an object of UserController. Typically in JSPs, you need to have a tag to create that object. https://examples.javacodegeeks.com/enterprise-java/jsp/use-bean-in-jsp-page/

But in Spring based application, in which all objects are managed by the container, you need to provide a mechanism to fetch the appropriate object from the container. Take a look at this thread: retrieve Bean programmatically

  • I certainly didn't understand what it meant.. My question is.. There is another method in userController called create(userDto user). I can access it easily by creating userController object uC (uC.create(userDto)) from jsp. But in this case it is a list type. So how can i access it? uC.login() didn't work. –  Oct 13 '19 at 12:02
  • It's somehow strange, nothing should be wrong in your JSP page; perhaps the problem is related to the controller and Java code. Can you debug the Java code by your IDE and check whether it returns the list successfully? – Ahmadreza Sedighi Oct 13 '19 at 13:45
0

Get the user controller method

<%
UserController userController = new UserController();
List<LoginDto> list = userController.login();
%>
Dino
  • 7,779
  • 12
  • 46
  • 85
Amit Kumar
  • 31
  • 4