I have a page call view_main and view_course. I use the logged in details to get data from the database and display it to the view_main page. Afterward the user can click the links generated in the view_main page and be forwarded to view_course page and here is my problem, how do I forward the page to view_course and forward the courseID as well for me to get the data from the database to display it with the view_course servlet?
I tried this but it doesn't work.
Part of view_main HTML code
<#list courses as course>
<div class = "carousel-tile">
<form action="view_course" method="post">
<button type="submit">
<input type="hidden" name="courseID" value=${course.kid}>
<h4>${course.kid} ${course.name}</h4>
<p>${course.description}</p>
</button>
</div>
</#list>
Java viewMainServlet doGet
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try(RegisterStore registerStore = new RegisterStore()){
User user = (User) request.getSession().getAttribute("user");
List<Course> courses = registerStore.getRegisteredCourses(user.getUid());
List<Course> availableCourses = registerStore.getNonRegisteredCourses(user.getUid());
registerStore.complete();
request.setAttribute("numberOfColumns", courses.size());
request.setAttribute("availableCourses", availableCourses);
request.setAttribute("courses", courses);
} catch (Exception e){
throw new StoreException(e);
}
request.getRequestDispatcher("/view_main.ftl").forward(request, response);
}
question from:
https://stackoverflow.com/questions/66067771/how-to-create-an-link-in-html-that-will-also-send-data-to-java-backend 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…