在Java Server Pages (JSP) 中,如果你需要在JSP页面中访问Controller实例,通常有以下几种方法:

方法一:使用Spring的依赖注入

如果你使用的是Spring框架,可以在Controller中添加一个依赖注入注解,然后在JSP页面中注入这个Controller。

jsp怎么找到controller实例,jsp如何找到Controller实例  第1张

在Controller类中添加一个依赖注入的成员变量:

```java

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.GetMapping;

@Controller

public class MyController {

private final MyService myService;

public MyController(MyService myService) {

this.myService = myService;

}

@GetMapping("