Display HashMap values in JSP using Taglib in struts

Hi ,
I am new to struts and JSTL. I am developing Discussion Forums using Struts.
I have HashMap object with(key & values) in My Action class.
I want to diplay in my JSP as a List with html:links to do other process.
How can I display HashMap values in my JSP. Which is the best way to display
My intenetion is maxmum avoiding <%%> code in jsp.
Which is the best way to display ?
Can I diplay using taglib which is generic tag for any collection object ?
Can any one help me ASAP.
thanks
Chandra

Hi Riaz,
You can use same code in JSP
Java Code
import java.util.*;
class TestHashMap
public static void main(String args[])
HashMap hm=new HashMap();
//store some Objects.
hm.put("Rajib Sarma","100");
//duplicate keys are not allowed.
hm.put("Rajib Sarma","200");//The value "100" is replaced by "200".
hm.put("Sazid Ahmed","200");
//Display the contents of the HashMap
System.out.println("Displaying all the keys/values.\r\n");
System.out.println("Key\t\tValue\r\n");
//get all the keys
Collection c=hm.keySet();
//obtain an Iterator
Iterator i=c.iterator();
while(i.hasNext())
//obtain a key
Object key=i.next();
//obtain the value of the key
Object value=hm.get(key);
System.out.println(key +"\t" + value);
}//while ends
}//main ends
}

Similar Messages

  • Displaying Hashmap values in JSP using struts taglib

    Please can any one provide me the solution for the below query,
    I have stored hasmap key as string and value as arraylist, can any one suggest how to display the hashmap values(arraylist) in table format in jsp using struts taglib.
                             HashMap hsMap=new HashMap();
                             ArrayList arrList = new ArrayList();
                             arrList.add("filesize");
                             arrList.add("filelength");
                              hsMap.put("filename",arrList);
               In jsp i want to display filename and filesize in table format.

    Read this documentation:
    http://struts.apache.org/struts-doc-1.2.x/userGuide/struts-logic.html#iterate

  • Syntax to pass parameter value to jsp using href in out.println

    Hi,
    I have the URL in the form as mentioned below:
    <a href="b2c/marketing/showDocDetail.jsp"> <%=doc_no%></a>
    I've created the hyperlink using href tag to the document number in the jsp using the below syntax.
    <% String a1 = "Document ";
           String a2 = "<a href=\"";
           String a3 = "marketing/showDocDetail.jsp\">";
           String a4 = doc_no;
           String a5 = "</a>";
    out.println(a1a2a3a4a5);
    %>
    When clicked the doc_no is passed to backend RFC and export parameter is retrieved to result.jsp where values along with doc_no are displayed.
    the value after clicked is not being passed to action.java class that does the retreival.
    Needful, backend class, bom, entry in config.xml is all maintained.
    Please help me out with the syntax to pass the parameter value into java class

    Hi Bharathi,
    try below.
    <%
           String a1 = "Document ";
           String a2 = "<a href=\"";
           String a3 = "marketing/showDocDetail.do?docNo=";
           String a4 = doc_no;
           String a5 = " \">";
           String a6 = doc_no;
           String a7 = "</a>";
    out.println(a1+a2+a3+a4+a5+a6+a7);
    %>
    I assume doc_no is java variable contains value of document number
    Now create action entry in config.xml file. Suppose "actionDoc.java" class process it.
    <action path="/marketing/showDocDetail" type="com.xyz.actions.actionDoc">
                   <forward name="success" path="/marketing/showDocDetail.jsp"/>
                   <forward name="error" path="/marketing/showDocDetail.jsp"/>
    </action>
    We are passing parameter docNo=doc_no to action class actionDoc.java in this class you can retrieve request parameter docNo from request object and then process it as you want.
    Let me know if you face any problem or error.
    eCommerce Developer
    Edited by: Ecommerce Developer on Nov 9, 2009 8:35 AM

  • How to display array values in jsp of screen flows

    Hi,
    can u please help me .
    I am having one array variable i have stored all the values but i have to display that in JSP page .how to display
    Edited by: user12171025 on Nov 4, 2009 11:11 PM

    Hi,
    I think that its necessaries to use AJaX.
    I am implemeting something like that.
    I have a input text that works like a filter and depends on what my user types in input text I populate my table with some information.
    In order to do that, I put in my JSP a div with an Id and I used ajax, like that:
    function ajaxFunction()
              var xmlhttp;
              if (window.XMLHttpRequest)
              xmlhttp=new XMLHttpRequest();
              else if (window.ActiveXObject)
              // code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              else
              alert("Your browser does not support XMLHTTP!");
              xmlhttp.onreadystatechange=function()
                                                      if( xmlhttp.readyState==4 )
                                                           document.getElementById("tabelaResponsaveis").innerHTML = xmlhttp.responseText;
         var resp = "<f:invokeUrl var='solicitacao' methodName='getResponsaveis'/>";
         xmlhttp.open("POST",resp,true);
         xmlhttp.send(null);
    getResponsaveis is a method inside my BPM that returns a HTML code (the table HTML code with all the information that I need to show.
    I Hope to help
    Thanks Marcos

  • I want to display BLOB image in JSP Using  html tags IMG src=

    GoodAfternoon Sir/Madom
    I Have got the image from oracle database but want to display BLOB image using <IMG src="" > Html tags in JSP page . If it is possible than please give some ideas or
    Send me sample codes for display image.
    This code is ok and working no problem here Please send me code How to display using html tag from oracle in JSP page.
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="javax.swing.ImageIcon;" %>
          <%
            out.print("hiiiiiii") ;
                // declare a connection by using Connection interface
                Connection connection = null;
                /* Create string of connection url within specified format with machine
                   name, port number and database name. Here machine name id localhost
                   and database name is student. */
                String connectionURL = "jdbc:oracle:thin:@localhost:1521:orcl";
                /*declare a resultSet that works as a table resulted by execute a specified
                   sql query. */
                ResultSet rs = null;
                // Declare statement.
                PreparedStatement psmnt = null;
                  // declare InputStream object to store binary stream of given image.
                   InputStream sImage;
                try {
                    // Load JDBC driver "com.mysql.jdbc.Driver"
                    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                        /* Create a connection by using getConnection() method that takes
                        parameters of string type connection url, user name and password to
                        connect to database. */
                    connection = DriverManager.getConnection(connectionURL, "scott", "root");
                        /* prepareStatement() is used for create statement object that is
                    used for sending sql statements to the specified database. */
                    psmnt = connection.prepareStatement("SELECT image FROM img WHERE id = ?");
                    psmnt.setString(1, "10");
                    rs = psmnt.executeQuery();
                    if(rs.next()) {
                          byte[] bytearray = new byte[1048576];
                          int size=0;
                          sImage = rs.getBinaryStream(1);
                        //response.reset();
                          response.setContentType("image/jpeg");
                          while((size=sImage.read(bytearray))!= -1 ){
                response.getOutputStream().write(bytearray,0,size);
                catch(Exception ex){
                        out.println("error :"+ex);
               finally {
                    // close all the connections.
                    rs.close();
                    psmnt.close();
                    connection.close();
         %>
         Thanks

    I have done exactly that in one of my applications.
    I have extracted the image from the database as a byte array, and displayed it using a servlet.
    Here is the method in the servlet which does the displaying:
    (since I'm writing one byte at a time, it's probably not terribly efficient but it works)
         private void sendImage(byte[] bytes, HttpServletRequest request, HttpServletResponse response) throws IOException {
              ServletOutputStream sout = response.getOutputStream();
              for(int n = 0; n < bytes.length; n++) {
                   sout.write(bytes[n]);
              sout.flush();
              sout.close();
         }Then in my JSP, I use this:
    <img src="/path-to-servlet/image.jpg"/>
    The name of the image to display is in the URL as well as the path to the servlet. The servlet will therefore need to extract the image name from the url and call the database.

  • Passing values to JSP using HTML

    I have 2 jsp�s (First.jsp, second.jsp).
    I have one a:href on First.jsp where it goes to Second.jsp , and also it needs to take some ID values from First.jsp to Second.jsp.
    Below is my code (First.jsp):
    <h:inputHidden id =�employeeId� value = �#{employee.employeeID}�
    <h:inputHidden id =�applicationId� value = �#{employee.appliationID}�
    Below iy my href:
    <a href = �/jsp/Second.jsp� > Add Application </a>
    How can I send values of employeeId and applicationID to Second.jsp , on clicking Add Application on first.jsp
    Any suggestions

    That's JSF.
    You may find this article useful: http://balusc.xs4all.nl/srv/dev-jep-com.html

  • Display null value:Report Filter using Show/hide report filter

    Hi,
    Is there any documentation from SAP BO that says "Report Filters don't display nulls."?
    Report Filter as in by clicking the Show/Hide Report Filter in the Infoview toolbar.
    Please help.
    Thank you.

    Hai
    u r Thread is similar  to
    http://www.forumtopics.com/busobj/viewtopic.php?p=848982&sid=2a66a2348c7042773baaf7bfd10241b2

  • Passing value from JSP to Action in Struts

    Hi,
    I am populating JSP page with rows retrieved from the database and
    represented as a List of Beans in forEach loop:
    <c:forEach var="list" items="${OperationsForm.OperationsList}">
    <c:choose>
    <c:when test="${list.isCompleted =='Y'}" >
    <td width="100">Completed</td>
    <td width="100"> </td>
    </c:when>
    <c:otherwise>
    <td width="100">Pending</td>
    <td width="100"><input type="image" onclick="
    rowId=value; form.action='action.do?command=notify'"
    value="${list.OperationId}" />
    </td>
    </c:otherwise>
    </c:choose>
    </tr>
    </c:forEach>
    Have hidden field: html:hidden property="rowId" value="-1"/>
    User is clicking the button corresponding to one of the rows
    and I need to pass the value of that rowId to the Action class, so it does
    something in the database [action completed]
    Now how do I pass it , is that the right way of doing it with calling
    request.getSession().getAttribute(rowId) in the Action class ?
    As of now I am getting Javascript error "Object doesn't support this
    property or method", complaining about rowId=value;
    Using Struts 1.3
    Please help !
    TIA,
    Oleg.

    So what you are saying is that I should add rowId here:
    <input type="image" onclick="form.action='action.do?command=notify&rowId='
    ${list.OperationId}"/> , correct ?
    I am not sure that it will work, especially with Struts tag.
    I will probably try something like:
    <html:submit onclick="form.action='action.do?command=notify'" value="${list.OperationId}">
    I am relatively new to Struts, so now sure what will work or not and how to do it better. How do I catch the submitted value in the Action in either of these 2 cases, via action.getSession().getProperty("rowId") /
    action.getSession().getProperty("submit") ?
    I would probably do it as a URL rather than changing the action of the form.I will have to create a new action anyway to process that row [which is sending user e-mail regarding that row data/event].
    Is the id the only thing you have to pass in?
    Or do you need other values from the screen?Selected rowId is probably the only thing I care about, can access values from the Form in Action.
    Thank you,
    Oleg.

  • How to display the data in XML files into JSP using Jdeveloper.

    Hi All,
    I have two XML files one XML file has the view names and the other has the table names of a particular views, how to display the data in JSP using JDeveloper where when i click a particular view the list of tables of that particular view from XML file two should be displayed in JSP Page.
    Are there any reference documents, regarding the above process please can anyone guide through how to do it.

    Let the servlet ask your business tier to provide the data, then stuff it into beans, and pack those into the Session instance. Then forward the request to the JSP, let the JSP get those beans and display them.

  • Crystal report in JSP using activeX viewer

    Hi,I'm trying to integrate JSP and crystal report.
    can you give me a sample code to display crystal report in JSP using activeX viewer(not pure HTML)
    I'm using crystal report 9,there are ASP sample come with CR9,but no JSP.also I don't want use Crystal Enterprise9 even I know the URL reporting may be the eaier way.

    Hi,I'm trying to integrate JSP and crystal report.
    can you give me a sample code to display crystal
    report in JSP using activeX viewer(not pure HTML)
    I'm using crystal report 9,there are ASP sample come
    with CR9,but no JSP.also I don't want use Crystal
    Enterprise9 even I know the URL reporting may be the
    eaier way.Hi, did u manage to get the ActiveX Viewer up with JSP? I'm also trying to do the same thing. If you could, pls kindly email me the basic source codes to [email protected]? Thanks

  • TextInput (with lookup reference) which doesn't display database value

    Hi,
    We are using JHeadstart 11.1.1.0.31 and have a problem with a field (varchar2 displayed as textInput) which references a lookup table. The value which is displayed is not the database value we expected but a number which seems to be the number of the record in the table. When we display the referenced field from the lookup table, we see the correct database value.
    When we run the service in the Model layer, this problem doesn't exist.
    Thanks for helping us,
    Petra Wernars / Jonathan Damen

    Hi,
    The issue here is that:
    - a model LOV has been defined on the View Object attribute
    - you are using a normal texinput to display the value
    - you are using something like #{bindings.MyField.inputValue} to bind the value
    The 'inputValue' will in this case assume a choicelist is rendered (because of the model LOV definition) so it will give the index within the choicelist, instead of the normal VO attribute value!
    Use 'attributeValue' instead in this case, so you will always show the real attribute value. Or remove the model LOV if you are not using it. Notice that with default options selected, JHeadstart will create a model LOV on each column that references another viewobject.
    Regards
    Evert-Jan de Bruin
    JHeadstart Team

  • How can i display the values in the vector in a jsp using jstl

    in a task i am recieving a vector in a jsp... how can i display those vector values in the jsp using jstl.... plz help me
    thanks in advance

    <%
    here you got vector say; v
    pagecontext.setAttribute("varname",v);
    %>
    <c:forEach var="i" items="${varname}">
    <c:out value="${i}">
    </c:forEach>

  • JDEV 10G: how to display the value of the line chart using jChart in JSP

    I have draw the line chart in JSP using the JChart and now I wan to display the value label in the line there..
    but the value wasn't show..
    anyone can help me..
    thx..

    Hi,
    what I do understand, you want to display the value of each point in your Line Graph.
    I guess you will be having BIGraph.xml file. In this file check the "Show Data Tips When Mouse is over bars" checkbox.
    Lets try with this.
    --Abhijit                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Jsp ok but IDE display errors in javascript+tags and taglibs include file

    Hi,
    The JDev 10.1.3 IDE display errors on running JSP in following cases:
    1) When tag libs declaration in include file.
    2) When jstl/struts tags are used in javascript
    JDev 10.1.2 didn't diplay those errors
    More details:
    extracts:
    Type of error: Character data not allowed in head
    alert("Your session has been closed automatically after a long period of inactivity.\nOR\nYou used an invalid or old bookmark.");
    javascript comments: (use for debugging)
    // alert("agt: "+agt+", is_ie: "+is_ie);
    Type of error: element <used tag> not expected here
    <fmt:bundle basename="com.photoswing.webview.MainshopAppMessageResources">
    alert("<fmt:message key="alert.timeout.noRedirection"/>");
    </fmt:bundle>
    JDev 10.1.3 has no javascript editor, so it should ignore the content of <script> .. </script>
    Regards
    Fred

    Hi,
    Same message but with formatting tags.
    Closing tag is [ / code ] without blanks.
    Thanks to Didier,
    IDE displayed errors => jsp runs and compiles ok.
    It is not obvious to reproduce those errors because they vary upon external or internal tag declaration.
    Remark:
    I tried replacing jsp tag declaration:
    <%@ include file="../../helper/TagLibsInclude.jsp"%>by simple file but it doesn't help:
    <%@ include file="../../srcInclude/tagLibs.inc"%>Case 1) all tag declaration are external but jstl c and fmt also internal:
    <%@ include file="../../helper/TagLibsInclude.jsp"%>  
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
    <%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>Element c:out not expected:
    =====================
    <c:set var="numberOfRows">
      <c:out value="${bindings.LoadedPhotos}" />
    </c:set>Element logic:messagesPresent not expected
    ==================================
         </tr>
        <logic:messagesPresent message="true" >
            <html:messages message="true" id="msg">
             <tr>
              <td colspan="5" class="txtMed txtBold">
                 <c:out value="${msg}"/><br/>
              </td>
             </tr>
            </html:messages>
        </logic:messagesPresent>
        <tr>Element fmt:param not expected .
    ========================
                  <fmt:message key="event.photoCommentInLang.prompt">
                   <fmt:param value="${pageScope.langName1}"/>
                  </fmt:message>
    ..Case 2) all tag declaration are external
    Element set not expected .
    ===================
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <c:set var="sourceId" value="${bindings.EventId.attributeValue}"/>
      <c:set var="sourceId1" value="${bindings.AlbumId.attributeValue}"/>
    ...Element bundle not expected .
    ======================
    </head>
    <body>
    <fmt:bundle basename="com.photoswing.webview.MainshopAppMessageResources">error: Character data not allowed in head
    =============================
    Example:
    <script language="JavaScript" type="text/javascript">
    function FL_init() {
      <c:if test="${not empty requestScope.SessionWasInvalid}">
        alert("<fmt:message key="general.loggedIn.timeout"/>");
        location.href="<c:url value="/accountLogin.do"/>";
      </c:if>
    </script>Regarding my workaround:
    You don't have to remove the tag declaration, but I prefer to keep my jsp as clean as possible.
    But I found another problem, this time it's a serious one, when you reformat the source ALL tag prefixes are removed.
    Example
    <c:set ... becomes <setOther example:
      <c:set var="numberOfRows">
      <c:out value="${bindings.LoadedPhotos}" />
      </c:set>becomes:
        <set var="numberOfRows">
         <out value="${bindings.LoadedPhotos}"/>
        </set>Good luck!
    Fred

  • Using a variable as a value in jsp:param

    I was wondering, I have a String variable, vid_1, and want to use a jsp:include and pass that in as one of the parameters. How can I do this? I have to do some testing to make sure vid_1 is valid and set a default if not. It contains a number referring to which video needs to be displayed.
    Is there anyway I can get this value to be used in jsp:param value?
    John

    RahulSharna wrote:
    Well,First thing you haven't pharsed your question properly.
    Anyways as per my understading.
    The first thing is make use of in this case as your defined requirement states you need to make use of variables of both the JSP's which need compile time include not at the runtime.use of
    <%@ include file="url" %>would be more appropriate as you want to use the variable of parent jsp to the child one.
    Anyways if you are thinking to apply a solution using <jsp:include/>
    <jsp:include page="url">
    <jsp:param name="paramName" value="<%=stringVariable>"/>
    </jsp:include>and extract the paramName's corresponding value as a request parameter in other JSP.
    Hope that might answer your question :)
    REGARDS,
    RaHuLRaHul,
    Thanks for the reply. The second example you gave is what I was trying to do. I thought I did exactly what you have there and it was not working. I will check it over again and post back on here when I have a chance.
    For now I was trying to use c:set to save the variable in the request and then using the EL expression ${requestScope.variable} to put it in the <jsp:param> element. I had some things working and others not when I quit. Hopefully tomorrow I can give you a full report and we can get this worked out.
    Maybe my problem is something else? Look at this post of mine:
    http://forum.java.sun.com/thread.jspa?threadID=5236252&tstart=10
    Thanks so much for the help.
    John

Maybe you are looking for

  • Access to Adobe Photoshop CS3 w/ Adobe Creative Cloud

    Is there a possibility to have access to Adobe Photoshop CS3 with my Adobe Creative Cloud account?

  • Is It Normal? I have order 3/06/10 ipad 16gb 3g, and still nothing!..

    Hello, is it normal to wait so much for get ipad 16gb 3g?? almost 1 month.. and even no information about when i will get it, i live in italy and did the order in data trade of rimini, they still dont know when i will get it! Someone can tell me if i

  • Modify the ASMA without defining the Sender and Receiver Interface

    Hi All, I am developing a scenario where I am picking files from NFS and putting in FTP. For this I am using only the ID and no IR content. So far so good. But Now we have a requirement to dynamically extract the target folder names from the File nam

  • Dialog box to get values during shipment

    hi gurus, when ever i save the shipment after changing , i should get a pop up and this pop up contains few fields which are populated by user and once he presses enter then it should save the entreis in the z table, how cna it be acheived can i call

  • Portege R30-A-196 won't turn off, blocks

    I bought a Toshiba Portege R30-A-196 there is 1 month. From early exhibits the same problem. Occasionally, when I shut down presents the Toshiba screen saver, the message "shut down" and blocks. If i wait one hour didn't shut down. Some times, if is