2 years ago

#27061

test-img

Jasmine Mel

Request Mapping in Java EE

in springMvc we can use in controllers the mapping like so

for example for url=projectName/student/all

@Controller
@RequestMapping("/student")
public class StudentController {
   //...
   @GetMapping("/all")
   public String listStudents() {
   //...
  @GetMapping("/add")
   public String addStudent() {
   //...

I'm need to do the same thing but now I'm not using springMvc but Java EE with Hibernate, and I want to be able to call different functions based on the url, like url=projectName/student/all and url=projectName/student/add

in StudentServlet

@WebServlet("/student")
public class StudentServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
   

public ProfesseurServlet() {
    super();
}
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  // if(the the url is `projectName/student/add`)
  //do ....

  // if(the the url is `projectName/student/all`)
  //do ....

I've tried :

  String path= request.getRequestURI().substring( request.getContextPath().length() );
    if ( chemin.startsWith( "/.." )//...

but I've got this error

HTTP 404 Status - Not Found
The requested resource is not available.

Thank you in advance

java

jakarta-ee

mapping

hibernate-mapping

0 Answers

Your Answer

Accepted video resources