0

I am a beginner at Java Servlets and JSP. I am trying to print a simple string which is passed from the servlets. However when i try to print the attribute using

<h2><c:out value="${name}" /></h2>

i get the output as ${name}. I tried searching for related posts, and also executed solutions i read, But i am not able to figure this basic thing out. Please Help me.

Here is my Servlet Code

package com.crudproject.CrudControllers;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CrudServlet
 */
@WebServlet("/")
public class CrudServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String name = "Afras";
        RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/greetings.jsp");
        request.setAttribute("name", name);
        rd.forward(request, response);
    }
}

Here is my JSP PAGE

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<html>
<body>
<h2>Hello World!</h2>
<h2><c:out value="${name}" /></h2>
</body>
</html>

JSTL dependency in POM.XML

<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>here
Afras Khan
  • 63
  • 1
  • 3
  • What is your servlet version from `web.xml`? Show the top part of your `web.xml` file where you declared `` – Bogdan Jan 23 '21 at 09:20
  • Archetype Created Web Application java.lang.Exception /Error.jsp – Afras Khan Jan 24 '21 at 18:17
  • Version 2.3 is ancient. You should use a newer version. See the post that was marked as [duplicate](https://stackoverflow.com/questions/30080810/el-expressions-not-evaluated-in-jsp) for your question for more details on how to do that. – Bogdan Jan 25 '21 at 09:21

0 Answers0