0

I have a problem when calling a servlet, the label that I'm calling in the JSP file is not visible.Somehow, attribute of the request is not being set up by servlet.It has something to do with dependencies...killed almost 2 days with this. Thanks!

Servlet Class

package com.example.JSP_Hope;

import java.io.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "DemoServlet", value = "/DemoServlet")
public class DemoServlet extends HttpServlet {


public void
doGet(@org.jetbrains.annotations.NotNullHttpServletRequestrequest,HttpServletResponse response) throws IOException, ServletException {
        String name="Sergiu";

        request.setAttribute("label",name);
        RequestDispatcher requestDispatcher= request.getRequestDispatcher("index.jsp");
        requestDispatcher.forward(request,response);

        }


    public void destroy() {
    }
}

index.jsp

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<!DOCTYPE html>
<html>
<head>
    <title>JSP - Hello World</title>
</head>
<body>
<h1>
</h1>
<br/>

<a href="DemoServlet">Demo Servlet Called</a>
${label}
</body>
</html>
asezoh
  • 1
  • 1

0 Answers0