473,236 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,236 software developers and data experts.

How i can populate all fileds dynamically in jsp page based on contents found in xml

How i can populate all fileds dynamically in jsp page based on contents
found in xml file?I have written jsp servlets and java class file.
i transferred automatic data from jsp to servlet then to java class
which creates a xml file based on values entered in dynamic jsp page.
Now i want to read all those values entered to xml in my other jsp
page.But as dynamic values can be any in no i don't know how could i
populate all those in my jsp again which sholud read all data from xml.
Items can be any so like we create them dynamically with fileds
item title/link/description.I need to read them from xml file and display them dynamically here.

Expand|Select|Wrap|Line Numbers
  1. <%@ page  language="java"
  2. import="java.io.*"
  3. import="java.util.*"
  4. import="org.jdom.*,
  5.         org.jdom.input.*,
  6.         org.jdom.output.*"
  7. %>
  8. <%
  9.      String s1=null,s2=null,s3=null,s4=null,s5=null,s6=null;
  10. %>
  11. <%
  12.  try{SAXBuilder builder = new SAXBuilder();
  13.       Document doc = builder.build(new File("c:\\Rss.xml"));
  14.       Element root = doc.getRootElement();
  15.       doc.getParent();
  16.       Element channel = root.getChild("channel");//channel
  17.  
  18.       s1=channel.getChild("title").getText();
  19.       s2=channel.getChild("link").getText();
  20.       s3=channel.getChild("description").getText();
  21.  
  22.       List item = channel.getChildren("item");//item
  23.       Iterator itr = item.iterator();
  24.        while (itr.hasNext()) {
  25.         Element items = (Element) itr.next();
  26.         s4=items.getChild("title").getText();
  27.         s5=items.getChild("link").getText();
  28.         s6=items.getChild("description").getText();
  29.              }
  30.  }catch (Exception e) {
  31.       e.printStackTrace();
  32.     }
  33. %>
Expand|Select|Wrap|Line Numbers
  1. <head><title>RSS Channel Display Page</title></head>
  2. <script type="text/javascript">
  3. var browser_name=navigator.userAgent;
  4. function getDeleteButtonForGivenID(idname)
  5. {
  6.     var result="";
  7.     result+="<span style='font-size:16px'>";
  8.     result+="<table cellspacing='0' cellpadding='0' border='0'>";
  9.     result+="\n        <tr><td class='button_side'>";
  10.     result+="\n                <img
  11. src='/castylesr2/images/pagebutton-start.png' width='0' height='0'
  12. id='button_"+idname+"startimg' alt='' />";
  13.     result+="\n            </td>";
  14.     result+="\n            <td class='button_center_new'
  15. id='button_"+idname+"buttoncenter' >";
  16.     result+="\n                <button type='button' value='delete'
  17. onclick='callDeleteThis('task_table_"+idname+"');'
  18. id='button_"+idname+"' title='delete this task'
  19. onmouseover='document.getElementById('button_"+idname+"').className='buttons_onmouseover';document.getElementById('button_"+idname+"buttoncenter').className='button_center_onmouseover';document.getElementById('button_"+idname+"startimg').src='/castylesr2/images/pagebutton-start-over.png';document.getElementById('button_"+idname+"endimg').src='/castylesr2/images/pagebutton-end-over.png';'
  20. onmouseout='document.getElementById('button_"+idname+"').className='buttons';document.getElementById('button_"+idname+"buttoncenter').className='button_center_new';document.getElementById('button_"+idname+"startimg').src='/castylesr2/images/pagebutton-start-over.png';document.getElementById('button_"+idname+"endimg').src='/castylesr2/images/pagebutton-end-over.png';'>";
  21.     result+=                    "delete";
  22.     result+=                "</button>";
  23.     result+="\n            </td>";
  24.     result+="\n            <td class='button_side'>";
  25.     result+="\n                <img
  26. src='/castylesr2/images/pagebutton-end.png' width='0' height='0'
  27. id='button_"+idname+"endimg' alt='' />";
  28.     result+="\n            </td>";
  29.     result+="\n        </tr>";
  30.     result+="\n</table>";
  31.     result+="\n</span>";
  32.     return result;
  33. }
  34. function getElementBasedOnOS(idname)
  35. {
  36.     if(browser_name.indexOf("Mozilla") != -1)
  37.         return document.getElementById(idname);
  38.     else
  39.         return document.all[idname];
  40. }
  41. function callDeleteThis(trname)
  42. {
  43.     var tmp=document.getElementById(trname);
  44.     tmp.innerHTML="";
  45.  
  46. }
  47.  
  48. function getElementBasedOnOS(idname)
  49. {
  50.     if(browser_name.indexOf("Mozilla") != -1)
  51.         return document.getElementById(idname);
  52.     else
  53.         return document.all[idname];
  54. }
  55. function callAddMoreFunction(itemTitle, itemLink, itemDesc)
  56. {
  57.     tasks_counter++;
  58.     var obj = getElementBasedOnOS("tasks_table");
  59.     var counter=1;
  60.     var obj_id=null;
  61.     var id_name="task_table_"+counter;
  62.  
  63.     var main_obj=obj;
  64.     for (;obj_id=getElementBasedOnOS(id_name);)
  65.     {
  66.         if(obj_id==null)
  67.             break;
  68.         var temp_Compname_id=getElementBasedOnOS("itemTitle_"+counter);
  69.         if(temp_Compname_id==null)
  70.         {
  71.             main_obj=obj_id;
  72.             break;
  73.         }
  74.  
  75.         counter++;
  76.         id_name="task_table_"+counter;
  77.         obj_id=null;
  78.     }
  79.  
  80.     var string_tobe_printed="<table><tr><td
  81. id='task_table_"+counter+"'><table><tr><td
  82. style='font-size:12px;font-weight:bold;'> Serial No "+counter+"
  83. </td><td>"+getDeleteButtonForGivenID(counter)+"</td></tr>"+
  84.     "<tr><td width='30%'> itemTitle </td><td><input type='text'
  85. id='itemTitle_" +counter+ "' name='itemTitle_" +counter+ "'
  86. value='"+itemTitle+"' size='60'/> *</td></tr>"+
  87.     "<tr><td width='30%'> itemLink </td><td><input type='text'
  88. id='itemLink_" +counter+ "' name='itemLink_" +counter+ "'
  89. value='"+itemLink+"' size='60'/> *</td></tr>"+
  90.     "<tr><td width='30%'> itemDesc </td><td><textarea rows=5 cols=50
  91. id='itemDesc_" +counter+ "' name='itemDesc_" +counter+ "'
  92. >"+itemDesc+"</textarea></td></tr>"+
  93.  
  94.     "<tr><td width='30%'><br/></td></tr>" +
  95. "</table></td></tr></table>";
  96.  
  97.     if(main_obj.id == obj.id)
  98.     {
  99.        main_obj.innerHTML = main_obj.innerHTML + string_tobe_printed;
  100.          }
  101.     else
  102.     {
  103.         main_obj.innerHTML= string_tobe_printed;
  104.     }
  105.  
  106.     StoreFormData();
  107.     LoadFormData();
  108. }
  109. var TotalFormData=new Array();
  110. function StoreFormData()
  111. {
  112.     TotalFormData=new Array();
  113.     for(var i=1;i <= tasks_counter;i++)
  114.     {
  115.         var Task=new Array(3);
  116.         Task[0]=Task[1]=Task[2]="";
  117.  
  118. Task[0]=getElementBasedOnOS("itemTitle_"+i)!=null?getElementBasedOnOS("itemTitle_"+i).value:"";
  119. Task[1]=getElementBasedOnOS("itemLink_"+i)!=null?getElementBasedOnOS("itemLink_"+i).value:"";
  120. Task[2]=getElementBasedOnOS("itemDesc_"+i)!=null?getElementBasedOnOS("itemDesc_"+i).value:"";
  121.         TotalFormData[i]=Task;
  122.         Task=null;
  123.     }
  124.  
  125. }
  126.  
  127. function LoadFormData()
  128. {
  129.     for(var i=1;i <= tasks_counter; i++)
  130.     {
  131.       if(getElementBasedOnOS("itemTitle_"+i)!=null)
  132. getElementBasedOnOS("itemTitle_"+i).value=TotalFormData[i][0];
  133.       if(getElementBasedOnOS("itemLink_"+i)!=null)
  134.  
  135. getElementBasedOnOS("itemLink_"+i).value=TotalFormData[i][1];
  136.       if(getElementBasedOnOS("itemDesc_"+i)!=null)
  137.  
  138. getElementBasedOnOS("itemDesc_"+i).value=TotalFormData[i][2];
  139.  
  140.     }
  141.     TotalFormData=null;
  142. }
  143.  
  144. </script>
  145. <!-- End of the Dynamic Table structures -->
  146. </head>
  147. <body>
  148.     <body bgcolor="#ffffff">
  149. <form action="RssActionServlet"
  150. onsubmit="getElementBasedOnOS('total_tasks_no').value=tasks_counter;"
  151. id="tasks_form" method="post">
  152.         <input type="hidden" name="sendto" value="InsertAlternative"/>
  153.         <br>
  154. <table align="center" border="1">
  155. <tr align="left" valign="middle">
  156. <td align="right"><b>
  157. Channel Title:</b></td>
  158. <td align="right">
  159. <input name="channel_title" size="66" type="text" value="<%= s1
  160. %>"></td>
  161. </tr>
  162. <tr align="left" valign="middle">
  163. <td align="right">
  164. <b>Channel Link:</b></td>
  165. <td align="right"><input name="channel_link" size="66" type="text"
  166. value="<%= s2 %>"></td></tr>
  167. <tr align="left" valign="middle"><td align="right">
  168. <b>Channel Desc:</b></td>
  169.  <td align="right"><textarea name="channel_desc" rows="5"
  170. cols="50"/><%= s3 %></textarea></td></tr>
  171. </table>
  172. <table align="center" border="1">
  173. <tr align="left" valign="middle">
  174. <td align="right"><b>Item Title:</b></td>
  175. <td align="right"><input name="item1_title" size="66" type="text"
  176. value="<%= s4%>"></td>
  177. </tr>
  178.  <tr align="left" valign="middle">
  179. <td align="right"><b>Item Link:</b></td> <td align="right">
  180. <input name="item1_link" size="66" type="text" value="<%= s5%>"></td>
  181. </tr>
  182. <tr align="left" valign="middle">
  183. <td align="right"><b>Item Desc:</b></td> <td align="right">
  184. <textarea name="item1_desc" rows="5" cols="50" wrap = "virtual"><%=
  185. s6%></textarea></td>
  186. <br><td>
  187. <span style="font-size:16px"><caui:button type="submit" value="Edit"
  188. title="edit alternative" id="EditAlternative"
  189. onclick="callEditThisItem();"/>
  190. <br>
  191. <span style="font-size:16px"><caui:button type="submit" value="Delete"
  192. title="Delete this alternative" id="DeleteAlternative"
  193. onclick="callDeleteThisItem();"/>
  194. </td>
  195. </tr></table>
  196.          <table>
  197.             <tr>
  198.                 <td>
  199.                     <span style="font-size:16px"><caui:button
  200. value='Add More' title='Add More Alternatives. [Alternatives will be
  201. added in the end]' id='addMoreAlternatives' disabled='false'
  202. onclick="callAddMoreFunction('','','');"/></span>
  203.                 </td>
  204.                 <td>
  205.                     <span style="font-size:16px"><caui:button
  206. type='submit' value='Save' title='save alternatives'
  207. id='SaveAlternatives' disabled='false' /></span>
  208.                 </td>
  209.             </tr>
  210.         </table>
  211.         <br/>
  212.     </form>
  213. </caui:pagesection>
  214. <center><p></p></center></body></html>
  215.  
thanks
Vijendra
Oct 3 '06 #1
0 4005

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: alex | last post by:
Hi, I am looking for a way to populate an HTML table from an external local text file which looks like this: DATE/TIME LAT. LON. DEPTH. ML....
0
by: T.H.M | last post by:
This is the all code. Very simple and short. I need to populate a treeView in aspx page (web form) from XML file. I get en completion error:No overload for method 'TreeNode' takes '1' arguments ....
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
5
by: Arpan | last post by:
In order to populate any server control with data dynamically, is it ALWAYS NECESSARY to either BIND the DataSource to that server control or call the DataBind method of that server control? For...
0
by: Mike Collins | last post by:
I someone can please help, I am about at an end in trying to figure this out. I am adding some dynamic controls to my page (I found out that I was supposed to be doing that in the oninit event,...
4
by: Kevin Blount | last post by:
bit long winded this one, so stick with me: I'm trying to create a form that can go to one of 3 places, depending on various elements. My form control looks like this: <form runat="server"...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
1
by: eureka | last post by:
Hi folks, I am working on a webapplication using Jsp and JS. On my main Jsp(Jsp1) I have a table which is created dynamically inside a <divand contains all the backend-table's records as rows,...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.