0

I am using eclipse mars, JDK8, Tomcat 8.

this is my JSP page

<%@page import="com.cutm.pogo.User"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Page</title>
<link href="css/nodue_style.css" rel="stylesheet" type="text/css" />
<%@ page isELIgnored="false" %>
........
<%  User user = (User)session.getAttribute("LOGIN");
    out.print(user.getName());      %>
${user.name }

I have used out.print wich is working for me but not EL.

here is web.xml file

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">

please help to find mistake i have made.

Mat
  • 202,337
  • 40
  • 393
  • 406
Rakesh Ray
  • 62
  • 1
  • 9
  • you should access the LOGIN attribute instead. I can't remember if the EL will search in every scope. – AxelH Sep 19 '16 at 07:16
  • Thanks for your responce. In the code i Have used ${session.LOGIN.email } this is also not working – Rakesh Ray Sep 19 '16 at 07:21
  • `sessionScope` and not `session` ;) Look at these answers http://stackoverflow.com/questions/8309261/how-to-get-session-attribute-with-a-dynamic-key-in-el – AxelH Sep 19 '16 at 07:37
  • Thanks AxelH I took sometime to understand ${Login.name} working. – Rakesh Ray Sep 19 '16 at 07:41

2 Answers2

1

You should be able to access a session attribute directly using :

 ${sessionScope.LOGIN.name}

PS : I recommand you to never put Java code into the JSP since the EL and the JSTL exist. This will be more readable ;)

AxelH
  • 14,325
  • 2
  • 25
  • 55
0

Try this, hope it works: you need to make that variable available to access it in EL / JSTL. So using setAttribute, you can set the value.

    <%
    User user = (User)session.getAttribute("LOGIN");
    pageContext.setAttribute("userobj", user);
    %>
    ${userobj.name}
    
Senthil
  • 2,156
  • 1
  • 14
  • 19
  • Thank you this is working ... why session attribute value is not working. EL should work for every scope as per book – Rakesh Ray Sep 19 '16 at 07:24
  • This is a bad work-around, you should access the session attribute without the need of a java scriplet (never new how to call the java code in a JSP ;) ). Actually, using Java in a JSP is simply a bad design. – AxelH Sep 19 '16 at 07:35