I want to load a Courses page in my project with all the courses name in the database.
Here we can see an example edx courses page
The data about all the courses is loaded without any button click or from submission. So how can I do the same?
Here is what I tried for an simple example by sending a string to client1.jsp from Server1.java. But When I open client1.jsp it shows nothing .
File-Servlet1.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import javax.websocket.Session;
import java.util.*;
@WebServlet("/Servlet1")
public class Servlet1 extends HttpServlet {
private static final long serialVersionUID = 1L;
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
String name="Rahul";
HttpSession s=request.getSession(true);
s.setAttribute("myname", name);
response.sendRedirect("client1.jsp");
}
}
File-client1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div><h1>${myname}</h1></div>
<h1><%session.getAttribute("myname");%></h1>
</body>
</html>