0

I am working with Java 7, Eclipse Luna and WildFly 8.2.1.

In Eclipse I have a Dynamic Web Project with Dynamic Web Module 2.5 and Java 1.7.

I have a class PageStartTagSupport which extends TagSupport. In there I create a Map<String, Object> and set it as an attribute of PageContext:

package com.srh.tag;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class PageStartTagSupport extends TagSupport {

    @Override
    public int doStartTag() throws JspException {               
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("NAME", "SRH");

        pageContext.setAttribute("sessionsMap", map);

        return EVAL_BODY_INCLUDE;
    }

    @Override
    public int doEndTag() throws JspException {     
        return EVAL_PAGE;  
    }

}

I also have PageStartTagExtraInfo class which extends TagExtraInfo:

package com.srh.tag;

import javax.servlet.jsp.tagext.TagData;
import javax.servlet.jsp.tagext.TagExtraInfo;
import javax.servlet.jsp.tagext.VariableInfo;

public class PageStartTagExtraInfo extends TagExtraInfo {

    @Override
    public VariableInfo[] getVariableInfo(TagData data) {       
        return new VariableInfo[] {
            new VariableInfo("sessionsMap", "java.util.Map", true, VariableInfo.AT_BEGIN)   
        };      
    }

}

In WEB-INF I have a srhtags.tld file:

<?xml version="1.0" encoding="UTF-8"?>
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd ">
 <tlib-version>0.0</tlib-version>
 <short-name>NMTOKEN</short-name>
 <tag>
  <description>Session Tag</description>
  <name>pagestart</name>
  <tag-class>com.srh.tag.PageStartTagSupport</tag-class>
  <tei-class>com.srh.tag.PageStartTagExtraInfo</tei-class>
  <body-content>empty</body-content>
 </tag>
</taglib>

Now I create a login.jsp where I access that map and try to add a key and value to it.

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ taglib uri="/WEB-INF/srhtags.tld" prefix="srh"%>
<srh:pagestart/>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%
System.out.println("************* login.jsp: inside");

System.out.println("login.jsp: (original): sessionsMap=" + sessionsMap);
sessionsMap.put("NAME2", "SRH2");
System.out.println("login.jsp: (latest): sessionsMap=" + sessionsMap);

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
</body>
</html>

But problem is Eclipse is giving me error message on this line:

sessionsMap.put("NAME2", "SRH2");

And the error message is:

The method put(capture#5-of ?, capture#6-of ?) in the type Map is not applicable for the arguments (String, String)

Why Eclipse is giving me this error?

Thanks

2
  • "(capture#5-of ?" is actually part of the message? What happens when the VariableInfo has the proper type value?
    – nitind
    Feb 3, 2016 at 19:26
  • Yes "(capture#5-of ?" is part of the message. The error message I put above is the message Eclipse is giving me. I dont understand what do you mean by VariableInfo to has the proper type value? I did try new VariableInfo("sessionsMap", "java.util.Map<String, Object>", true, VariableInfo.AT_BEGIN) but still the same error.
    – srh
    Feb 3, 2016 at 20:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.