0

I am fully new in java, Seems its very silly question but I am facing issue while tying to print value from .JSP file, My output is always ${x} instead of value, Please someone help

Code Output ${x}

<html>
<body>
<% int x = 1;%>
<c:out value="${x}" />
</body>
</html>
  • You created a scripting variable. You are trying to access it as a scoped variable. Do you have the JSTL directive on your page? – rickz May 30 '22 at 23:28
  • Hi Yes, Below are contents in my jsp file <%@ 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" %> <% int x = 1;%> – Hukum Dev Narayan May 31 '22 at 15:24
  • If you want to access a scoped variable, then you must set it in scope. For example <% int x = 1; pageContext.setAttribute("x", x);%> – rickz May 31 '22 at 16:18
  • I tried, but still same output(${x}), not sure whether any issue in my eclipse <%@ 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" %> <% int x = 1; pageContext.setAttribute("x", x);%> – Hukum Dev Narayan May 31 '22 at 19:50
  • Show us the source code that your server sent to your browser. – rickz May 31 '22 at 23:31
  • Hi My code is as below 1. FirstPageController.java package com.skillsoft.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class FirstPageController { @RequestMapping(value = "/first") public String redirect_start_page() { return "first_page"; } } – Hukum Dev Narayan Jun 01 '22 at 08:16
  • 2. first_page.jsp <%@page language="java" contentType="text/html" pageEncoding="UTF-8" %> <%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> First JSP <% int x = 1; pageContext.setAttribute("x", x);%> – Hukum Dev Narayan Jun 01 '22 at 08:16
  • 3. index.jsp Summer Picnic

    Fantabulous University Summer Picnic Program

    Go to First Page
    – Hukum Dev Narayan Jun 01 '22 at 08:16
  • You posted your code. But, you didn't show us what your server sends to your browser. When you are looking at your page in your browser, right click your mouse and choose "View page source" from pop-up menu. Does your server evaluate the JSTL tag or just send it to browser? – rickz Jun 01 '22 at 15:35
  • You should edit your question and add code to it. Code in comments is hard to read. – rickz Jun 01 '22 at 15:37
  • Hi below are the view page source. – Hukum Dev Narayan Jun 01 '22 at 16:59
  • What is the output of a JSP with just ${"hello EL"} in it? – rickz Jun 01 '22 at 17:49
  • Hi output showing as ${"hello EL"} – Hukum Dev Narayan Jun 01 '22 at 18:16
  • EL is not working. Look at https://stackoverflow.com/questions/30080810/el-expressions-not-evaluated-in-jsp Do any of BalusC solutions work for you? – rickz Jun 01 '22 at 18:26
  • Hi, Really thankful to you, adding below on .jsp file worked for me, struggling from last few days, thanks once again <%@ page isELIgnored="false" %> Now output is "hello EL" – Hukum Dev Narayan Jun 01 '22 at 19:00

0 Answers0