powered by simpleCommunicator - 2.0.49     © 2025 Programmizd 02
Форумы / Java [игнор отключен] [закрыт для гостей] / Как сделать ссылку на JSP страницу в меню (Spring MVC + web)
2 сообщений из 2, страница 1 из 1
Как сделать ссылку на JSP страницу в меню (Spring MVC + web)
    #39818553
fallen2019
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
Я написал проект где хочу чтобы в меню при нажатии на вкладку "студенты" выпадал список и там в списке при нажатий на "список всех студентов" меня направило сразу же на страницу allStudents.jsp Я написал но почему пишет что страница не найдена

menutemplate.jsp

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
<%@page contentType="text/html" pageEncoding="UTF-8" isELIgnored="false"%>

      <nav>
  <ul class="topmenu">
    <li><a href="">Главная</a></li>
    <li><a href="">Образование</a></li>
    <li><a href="" class="down">Студенты</a>
      <ul class="submenu">
        <li><a href="allStudents.jsp">Список</a></li>

      </ul>
    </li>
    <li><a href="" class="down">Карьера</a>
      <ul class="submenu">
        <li><a href="">Бла бла</a></li>
        <li><a href="">Бла бла</a></li>
        <li><a href="">Бла бла</a></li>
        <li><a href="">Бла бла</a></li>
      </ul>
    </li>
    <li><a href="">Филиалы</a></li>
    <li><a href="">Выпусники</a></li>
    <li><a href="">Преподователи</a></li>
    <li><a href="">Пресс-Служба</a></li>
    <li><a href="">Клубы</a></li>
    <li><a href="">Портал</a></li>
    <li><a href="">Медиа</a></li>
    <li><a href="">Контакты</a></li>
    <li><a href="">О нас</a></li>



  </ul>
</nav>


Здесь раньше на этой странице я нажимал на кнопку "показать всех студентов" и меня сразу же направляло туда, но сейчас я хочу чтобы все работало через меню

index.jsp

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
<%@page contentType="text/html" pageEncoding="UTF-8" isELIgnored="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="style.css" rel="stylesheet">
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
        <link href="../css/style.css" rel="stylesheet" type="text/css">
        <style><%@include file="/css/style.css"%></style>
        <title>Home Page</title>

</head>
<body>
 <div class="bg">
        <div class ="pokaz">
            <form action="allStudents" method="post">
                 <input class="btn btn-primary" type="submit" value="Показать всех студентов">
            </form>

        </div>
    </div>
</body>
</html>


StudentController.java
Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
153.
154.
155.
156.
157.
158.
159.
160.
161.
162.
163.
164.
165.
166.
167.
168.
169.
170.
171.
172.
173.
174.
175.
176.
177.
178.
179.
180.
181.
182.
183.
184.
185.
186.
187.
188.
189.
190.
191.
192.
193.
194.
195.
196.
197.
198.
199.
200.
201.
202.
203.
204.
205.
206.
207.
208.
209.
210.
211.
212.
213.
214.
215.
216.
217.
218.
219.
220.
221.
222.
223.
224.
225.
226.
227.
228.
229.
230.
231.
232.
233.
234.
235.
236.
237.
238.
239.
240.
241.
242.
243.
244.
245.
246.
247.
248.
249.
250.
251.
252.
253.
254.
255.
256.
257.
258.
259.
260.
261.
262.
263.
264.
265.
266.
267.
268.
269.
270.
271.
272.
273.
274.
275.
276.
277.
278.
279.
280.
281.
282.
283.
package adil.java.schoolmaven.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletContext;
import adil.java.schoolmaven.entity.Student;
import adil.java.schoolmaven.service.StudentService;
import java.nio.file.FileSystemException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class StudentController {



    @Autowired
    private ServletContext servletContext;

    // Constructor based Dependency Injection
    private StudentService studentService;

    public StudentController() {

    }

    @Autowired
    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }


    @RequestMapping(value = {"/", "/index"}, method = RequestMethod.GET)
    public ModelAndView hello() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }

    // Get All Users
    @RequestMapping(value = "/allStudents", method = {RequestMethod.GET, RequestMethod.POST})

    public ModelAndView displayAllUser() {
        System.out.println("User Page Requested : All Students");
        ModelAndView mv = new ModelAndView();
        List<Student> studentList = studentService.getAllStudents();
        mv.addObject("studentList", studentList);
        mv.setViewName("allStudents");
        return mv;
    }

    @RequestMapping(value = "/addStudent", method = RequestMethod.GET)
    public ModelAndView displayNewUserForm() {
        ModelAndView mv = new ModelAndView("addStudent");
        mv.addObject("headerMessage", "Add Student Details");
        mv.addObject("student", new Student());
        return mv;
    }

    @PostMapping(value = "/addStudent")
    public String saveNewStudent(@RequestParam("name") String name,
            @RequestParam("surname") String surname,
            @RequestParam("avatar") MultipartFile file)
            throws IOException {

        if (file != null && !file.isEmpty()) {
            Student student = new Student();
            student.setSurname(surname);
            student.setName(name);
            student.setAvatar(studentService.saveAvatarImage(file).getName());
            studentService.saveStudent(student);
        }
        return "redirect:/allStudents";
    }



    @GetMapping(value = "/editStudent/{id}")
    public ModelAndView displayEditUserForm(@PathVariable Long id) {
        ModelAndView mv = new ModelAndView("/editStudent");
        Student student = studentService.getStudentById(id);
        mv.addObject("headerMessage", "Редактирование студента");
        mv.addObject("student", student);
        return mv;
    }

   @PostMapping(value = "/editStudent")

    public ModelAndView saveEditedUser(@RequestParam("id") Long id,

            @RequestParam("name") String name,

            @RequestParam("surname") String surname,

            @RequestParam("avatar") MultipartFile file) {
        ModelAndView mv = new ModelAndView("redirect:/allStudents");

       try {

            studentService.updateStudent(name, surname, file, studentService.getStudentById(id));

         }

        catch (FileSystemException ex){

            ex.printStackTrace();

         }

        catch (IOException e) {

             return new ModelAndView("error");

         }

        return mv;
    }

   @GetMapping(value = "/deleteStudent/{id}")
    public ModelAndView deleteUserById(@PathVariable Long id) {
         studentService.deleteStudentById(id);
        ModelAndView mv = new ModelAndView("redirect:/allStudents");

        return mv;

    }





 }package adil.java.schoolmaven.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletContext;
import adil.java.schoolmaven.entity.Student;
import adil.java.schoolmaven.service.StudentService;
import java.nio.file.FileSystemException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
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.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class StudentController {



    @Autowired
    private ServletContext servletContext;

    // Constructor based Dependency Injection
    private StudentService studentService;

    public StudentController() {

    }

    @Autowired
    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }


    @RequestMapping(value = {"/", "/index"}, method = RequestMethod.GET)
    public ModelAndView hello() {
        ModelAndView mv = new ModelAndView();
        mv.setViewName("index");
        return mv;
    }

    // Get All Users
    @RequestMapping(value = "/allStudents", method = {RequestMethod.GET, RequestMethod.POST})

    public ModelAndView displayAllUser() {
        System.out.println("User Page Requested : All Students");
        ModelAndView mv = new ModelAndView();
        List<Student> studentList = studentService.getAllStudents();
        mv.addObject("studentList", studentList);
        mv.setViewName("allStudents");
        return mv;
    }

    @RequestMapping(value = "/addStudent", method = RequestMethod.GET)
    public ModelAndView displayNewUserForm() {
        ModelAndView mv = new ModelAndView("addStudent");
        mv.addObject("headerMessage", "Add Student Details");
        mv.addObject("student", new Student());
        return mv;
    }

    @PostMapping(value = "/addStudent")
    public String saveNewStudent(@RequestParam("name") String name,
            @RequestParam("surname") String surname,
            @RequestParam("avatar") MultipartFile file)
            throws IOException {

        if (file != null && !file.isEmpty()) {
            Student student = new Student();
            student.setSurname(surname);
            student.setName(name);
            student.setAvatar(studentService.saveAvatarImage(file).getName());
            studentService.saveStudent(student);
        }
        return "redirect:/allStudents";
    }



    @GetMapping(value = "/editStudent/{id}")
    public ModelAndView displayEditUserForm(@PathVariable Long id) {
        ModelAndView mv = new ModelAndView("/editStudent");
        Student student = studentService.getStudentById(id);
        mv.addObject("headerMessage", "Редактирование студента");
        mv.addObject("student", student);
        return mv;
    }

   @PostMapping(value = "/editStudent")

    public ModelAndView saveEditedUser(@RequestParam("id") Long id,

            @RequestParam("name") String name,

            @RequestParam("surname") String surname,

            @RequestParam("avatar") MultipartFile file) {
        ModelAndView mv = new ModelAndView("redirect:/allStudents");

       try {

            studentService.updateStudent(name, surname, file, studentService.getStudentById(id));

         }

        catch (FileSystemException ex){

            ex.printStackTrace();

         }

        catch (IOException e) {

             return new ModelAndView("error");

         }

        return mv;
    }

   @GetMapping(value = "/deleteStudent/{id}")
    public ModelAndView deleteUserById(@PathVariable Long id) {
         studentService.deleteStudentById(id);
        ModelAndView mv = new ModelAndView("redirect:/allStudents");

        return mv;

    }





 }
...
Рейтинг: 0 / 0
Как сделать ссылку на JSP страницу в меню (Spring MVC + web)
    #39818566
fallen2019
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
fallen2019,

Сорри, что поспешил с вопросом у меня получилось

Код: java
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
<%@page contentType="text/html" pageEncoding="UTF-8" isELIgnored="false"%>
        
<header>
  <a href="" class="logo">Школа Программирования</a>
  <nav>
      <ul class="topmenu">
        <li><a href="">Главная</a></li>
        <li><a href="" class="submenu-link">Студенты</a>
          <ul class="submenu">
            <li><a href="allStudents">Список студентов</a></li>
            
          </ul>
        </li>
        <li><a href="">Проекты</a></li>
        <li><a href="">О нас</a></li>
        
      </ul>
    </nav>
</header>
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Java [игнор отключен] [закрыт для гостей] / Как сделать ссылку на JSP страницу в меню (Spring MVC + web)
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]