getting a blank page as output in my web browser when I run the following servlet

437 views Asked by At

I am getting blank page as output in my web browser when I run DemoServlet

note : I have used both doGet and doPost methods in my servlet instead of service method even though I am getting the same output.

The below is the following code

public class Student_Class {

    int RollNo = 0;
    String Name="";
    
    Student_Class(int RollNo,String Name) {
        this.RollNo = RollNo;
        this.Name = Name;
    }
    
    public int getRollNo() {
        return RollNo;
    }
    
    public String getName() {
        return Name;
    }
    
}

the above is my StudentClass

I have created a servlet like below

import java.io.IOException;
import java.io.PrintWriter;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

public class DemoServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        Student_Class Student = new Student_Class(1,"Name1");
        request.setAttribute("Student", Student);
        RequestDispatcher rd = request.getRequestDispatcher("display.jsp");
        rd.forward(request, response);
        
    }
}

and my jsp file is below the name of my jsp file is : display.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix= "c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
        
    ${Student}
</body>
</html>

my web.xml file is like below

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.5">
  <display-name>JSTL_Demo</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>Demo</display-name>
    <servlet-name>Demo</servlet-name>
    <servlet-class>Demo</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>Demo</servlet-name>
    <url-pattern>/Demo</url-pattern>
  </servlet-mapping>
  <servlet>
    <description></description>
    <display-name>DemoServlet</display-name>
    <servlet-name>DemoServlet</servlet-name>
    <servlet-class>DemoServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>DemoServlet</servlet-name>
    <url-pattern>/DemoServlet</url-pattern>
  </servlet-mapping>
</web-app>

I am using tomcat 10.0.10 as my server and eclipse as my IDE

please help me I am a beginner and I don't know much about jsp and servlets correct me if I have done anything wrong

click here to see the output on my browser

click here to see the project explorer

0

There are 0 answers