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
Similar Messages
-
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
ChandraHi 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
} -
How to assign bean value to a local variable in JSP using struts.
Hi everybody!
I've a problem that puzzled me on how to assign a bean value to a local variable like String in JSP using struts.
we can have someting like this to display the value
<bean:write name="detailService" property="status" />or
<bean:define id="theStatus" name="detailService" property="status"/>
This is country: <%=theStatus%>but an error occured when I tried like this:
String currentStatus = "<bean:define id="theStatus" name="detailService" property="status"/>";
or
String currentStatus = "<bean:write name="detailService" property="status" />";Is there a way to do this?.....
Any help pretty much appreciatedJava != JSP.
The <bean:define> and <bean:write> tags are custom tags meant to appear in the HTML section of a JSP file, as opposed to the scriptlet section. They actually get turned into java code as part of the translation process.
The <bean:write> tag naturally just writes out what you tell it to.
The <bean:define> tag defines a local variable, and gives it a value.
this should do it.
<bean:define id="theStatus" name="detailService" property="status" type="java.lang.String"/>
<%
String currentStatus = theStatus;
%>With the advent of JSTL, you shouldn't really need to use scriptlet code anymore. Personally I am for 0% scriptlet code in any jsp I write. -
How can I access to an EJB from a JSP, using a taglib?
I'm trying to access to an EJB from a JSP using a taglib,
and I get the example in
http://java.sun.com/j2ee/j2sdkee/techdocs/guides/ejb/html/Advanced5.html.
But I colund't run this example because in the weblogic Log appears many
errors when I run the JSP.
Can you help me?
Backing files is an option. If you need to do it from the controller, you
could use the Forward object. The forward object constructor can take a URL
object as a parameter. This should do the trick.
Regards,
Kunal
"Panji Aryaputra" <[email protected]> wrote in message
news:[email protected]..
Hi, you have to use backing file to get what you want. In my case, I am
using a page backing file. Perhaps a portlet backing file can do thatalso.
Cmiiw, the redirect header makes the page redirected only if the httpheader
has not been sent to client. In your case, the header has been sent (i.e.
the portal header.jsp has been displayed, etc). So the header need to be
sent before anything else sent to client browser. This is where thebacking
file comes handy.
hth
panji.a
"A Hagen" <[email protected]> wrote in message
news:[email protected]..
I'm using Bea Workshop 8.1 and trying to perform a redirect from inside
a
portlet
using HTTPServletResponse.sendRedirect(String url)... but nothing
happens
I tryed the same trick with a simple JSP, and that's ok, but portal
pages
obviously
catch the redirect somehow.
Please could you tell the correct way of redirecting the whole browser
to
another
page from inside portlets?
Thanks!!! -
[b]Data Grid in jsp using Struts [/b]
I need to develop a data grid in JSP using struts .
I am using Tomcat web server , Intellij IDEA IDE.
If any one has code, please sent it.
Thanks in Advance.hi,
Use Struts-Layout datagrid framework to full fill your needs
Related Topic link
here is the clear documentation for your topic
http://struts.application-servers.com/datagrid/index.html
here is the download link
(Struts-Layout datagrid framework)
http://deltha.uh.cu/java/docs/struts-layout-1.0-docs/download.html
related discuss
http://forum.java.sun.com/thread.jspa?threadID=5202989&messageID=9811082 -
Display date in jsp. using struts, JSTL
want to display today's date in format October 18, 2006
how to get today's date and how to display it in jsp?
I am using struts framwork and JSTL tags in my JSP.
Thanks.rizza_99 wrote:
The page underlines {<fmt:formatDate value="${now}" type="both" dateStyle="long" />} says
attributte value doesn't accept any expressionsWait, you said "the page underlines"?? So you're using an IDE? Are you sure that it a JSTL problem and not an IDE problem? Ignore the IDE and just execute the code. Does it work without any compilation errors or runtime exceptions? If so, then there's a problem in the IDE. -
Displaying list of items , in a jsp , using STRUTS--Correct approach
I have a requiremnet tht on click of a button , a list of items should be displayed on a jsp page , so tht a user can select items from tht list.
But the problem is tht , the list is very large(Conatins 1500 record).
So wht approach should i adopt.
One approach is tht , i have a link on my main.jsp , where user has a link (addItems) , and on clicking this link , another page(Items.jsp), opens up , where i dispaly the list of users , and user here can select multiple items , and then those items will be shown in Main.jsp.
Is this appraoch correct,
also plz tell me how can i incorporate previous and next functionality , so tht 20 records per page are shown
Can anyone tell me how 2 go abt it.
I m using STRUTS , and weblogic.Hiiii
When u want2 add textboxes dynamically,
then declare ur proprerty in action form as of type String[]
<form-bean
name="userForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="name" type="java.lang.String[]"/>
<form-bean>
When u add textboxes dynamically , and if the textboxes name is same as that in form bean,
then automatically this form bean property gets populated.
If u require further assistance do tell me -
Unable to use Struts taglib in JSF and Struts-tiles app
With the taglib correctly defined as follows,
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
I'm trying to use <link rel="stylesheet" href="<html:rewrite page='/WEB-INF/csslib/layout.css'/>" type="text/css"/> to pull in my stylesheet. But I get an error saying:
Apr 24, 2007 10:58:31 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet jsp threw exception
javax.servlet.jsp.JspException: ServletException in '/pages/layout.jsp': null
at org.apache.struts.taglib.tiles.InsertTag$InsertHandler.doEndTag(InsertTag.java:921)
at org.apache.struts.taglib.tiles.InsertTag.doEndTag(InsertTag.java:460)
at org.apache.jsp.pages.runTest_jsp._jspx_meth_tiles_insert_0(runTest_jsp.java:78)
at org.apache.jsp.pages.runTest_jsp._jspService(runTest_jsp.java:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
at org.apache.myfaces.tomahawk.application.jsp.JspTilesViewHandlerImpl.dispatch(JspTilesViewHandlerImpl.java:233)
at org.apache.myfaces.tomahawk.application.jsp.JspTilesViewHandlerImpl.renderView(JspTilesViewHandlerImpl.java:219)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:688)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:658)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:49)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Unknown Source)
If I take out the <html:rewrite> reference, it works like a charm.
What is the problem here?Hi,
Pls try application-config tag like this
<application-config>
<property name="PrivateSharingReference" value="com.sap.portal.htmlb">
</property>
<property name="SharingReference" value="com.sap.portal.runtime.application.soap">
</property>
</application-config>
Also check component tag is in this order
<component name="AddAccounts">
<component-config>
<property name="ClassName" value="Test">
</property>
<property name="JSP" value="pagelet/test.jsp">
</property>
</component-config>
<component-profile>
<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld">
</property>
</component-profile>
</component>
regards,
Sujesh -
Values from JSP to Struts Action Class
Dear All,
Am working on a small struts project, i want to get values from JSP in the Action class, i tried with sending variables using request through URL, it works fine, any other way is there to send the values from JSP to action class. Am not having any input fields in the JSP.I have links.
Thanks,
vyrav.I have a dispatch action for that am calling the action like this viewfiles.do?parameter=edit, and i have to send a variable ID from the same page, so am doing like this through java script, viewfiles.do?parameter=edit&id=10. Am able to get the id in the dispatch action edit, but when i start tomcat with security manager its not calling the action itself and its giving accesscontrol exception, but when i directly type viewfiles.do in URL its calling the action.
I dont know wats the problem, tomcat security manager not allowing this. Please help me.
Thanks,
vyrav. -
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 classHi 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 -
Approaches for Prepopulating dropdowns in Jsp using struts.
Hi,
I'm having a functionality working of pre-populating dropdowns using struts like:
ArrayList list = getRoles(); //This method will return list of roles
request.setAttribute("roles", list);
By setting this collection in the request it will be availbel to <html:select and <html:options> tags for pre-populating. My question here is do we need to set the list (that is to be displayed in the JSP) in request scope deliberately, or there are other better approaches as well to do the same, like using expression language and accessing the method directly.
Thanks,
Prashant.Why dont you use ActionForm.
declare a private variable
//variable
private List roles=null;
//methods
public List getRoles();
public void setRoles(List roles);and in ActionClass
ArrayList list = getRoles(); //This method will return list of roles
form.setRoles(list);This collection object will be available in the jsp forwarded from that action in the scope specified in the struts-config.
then use
<html:select>
<html:options collection="roles" labelProperty="name" property="id" />
</html:select> -
Dynamic Textboxes in JSP using struts
Hi all
I'm using JSP and Struts framework. I have two buttons Add row and delete row.(not submit buttons) on click i need to either generate or delete a row of textboxes. I able to do the same using javascript but the tag in that case is <input..>(normal HTML) and not <html:text> tag of struts.. Can i use the struts tag in jsp?? I tried but err... So any suggestions?
A sample code would be of great help.. Im still a beginner in this ocean of Java!
cyaIf the add/delete row buttons run in javascript, then you have to use the standard <input> tags.
The struts <html:text> tag is a JSP tag that just generates an <input> at the end of the day anyway (filling in the attributes automatically though)
As long as you name the controls consistent with what would have been produced by the struts tag, it should work perfectly well. -
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 PMHi,
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();
%>
ThanksI 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. -
Getting the values in jsp in struts
hi,
the thing is the values i had set in the form in the action as available
in the jsp page when i use neastes tld
but i am not able to find when i try to get in the request.getProperty(" ")
nither as request,getAttribute()
then how to get if i want to do some manuplation on the data in the jsp
thanks byeThere is no method request.getProperty() ... it should be request.getParameter(). The way you have worded your problem doesn't seem to give much information to me.
Maybe you are looking for
-
Posting only possible in periods 2002/03 and 2002/02 in company code 0001
All This is in the ongoing sequence where I am creating everything from the scratch(customers, material, prices etc).So far, I have been able to create and save the salesorder>deliver it>pick the items and then I was going to carry out the PGI and t
-
Orange stripe in Adobe Acrobat...
Hallo! I open a PDF document in Adobe Acrobat, type any letter characters from keyboard and the orange stripe appears in lower part of the screen just above the Dock. The stripe contains typed text. Once I type a numeric character the stripe disappea
-
Display Arrangement with 3 Monitors - Change Application from primary display for Mac
Hey guys, I have 3 monitors with 1 of them being a Wacom Intuos. Is there anyway to make certain applications load primarily on a different monitor than the one with the menu bar? For instance when I load Photoshop I want that whole program to load o
-
The font in internet explorer has changed to hand written font how do I get it back to normal
When I was using Google I typed in hand written fonts. Now all the words in Google or any other internet page are in a tiny hand written and unreadable font.
-
Mavericks doesn't always load my new gmail
After installing Mavericks I had to find some folders but more importantly my gmail emails have not always been showing up. I know this because my iphone has gmail emails that are not on my computer. I tried deleting the gmail accounts and reinstal