Solved

Adding table on a jsp  >>> URGENT<<<

Posted on 2004-09-04
54
680 Views
Last Modified: 2008-01-09
Hi!
I have asked this question earlier. But maybe people weren't clear about what I wanted to do. Hence I sending it agian. I really need to get this going asap. Sorry for the long question. But I need to get this done.
I am doing this in a jsp page:
Currently I am using the following for the expandable table logic:
<script language="javascript">
function sh(id)
{
  var oObj = document.getElementById(id)
  if(!oObj) return;

     oObj.style.display=(oObj.style.display=="none"?"block":"none");
}
</script>

<table border=1>
<tr onClick="sh('tr1')"><td>1</td><td>ABC</td><td>ABC is a name</td></tr>
<tr id="tr1" style="display:none;"><td></td><td colspan="2">
 <table border=1>
  <tr><td>1</td><td>A</td><td>A belongs to ABC</td></tr>
  <tr><td>2</td><td>B</td><td>B belongs to ABC</td></tr>
  <tr><td>3</td><td>C</td><td>C belongs to ABC</td></tr>
 </table>
</td></tr>
<tr onClick="sh('tr2')"><td>1</td><td>XYZ</td><td>XYZis a name</td></tr>
<tr id="tr2" style="display:none;"><td></td><td colspan="2">
 <table border=1>
  <tr><td>1</td><td>A</td><td>A belongs to XYZ</td></tr>
  <tr><td>2</td><td>B</td><td>B belongs to XYZ</td></tr>
  <tr><td>3</td><td>C</td><td>C belongs to XYZ</td></tr>
 </table>
</td></tr>
</table>
Firstly I want to provide a delete link next to each row when the tables are hidden and shown as rows and also I want to add another table instance or delete the table based on the users choice when he clicks the add button (to be provided at the bottom of the page) or delete link (as mentioned in my statement above) respectively.
 Like a shopping cart.
Actually I am talking about entire tables to be added or deleted and also shown or hidden :

eg:
initially the table is shown with all its fields empty.
then once you fill the fields and click the add button then it shows only some of the fields of the table and also a delete order option such as
 order# code#       description                                                  
  1         2wdeg     this is going to be used in the 3e44rt model               delete order
and also a another empty table as before, so that a user can fill in info for the new order and if he wants can click add or submit.
 if add is clicked then it shows only some of the fields of the table and also a delete order option such as
 order#  code#       description                                                  
  1         2wdeg     this is going to be used in the 3e44rt model               delete order
  2         77yytg     this is a attachment to the series ty77                        delete order
and also a another empty table as before, so that a user can fill in info for the new order and if he wants can click add or submit.

I am using JSP for all this with Jscript to control the show/hide table, as shown above.

 guess the following is the way i am planning to implement it:
Scenario:
======
My page consists of 2 jsp's. Each having a java a single object in which various fields are contained.
jsp page one  --> contains 1 java object (say user_info_object)
jsp page two  --> (this page is included in the page one , using jsp page include)  contains another java object (say order_info_object)
The java objects between both these pages need to communicate, as in if someone fills a value in userid (which is a field in the 1st java object, in the 1st jsp page) the order_info_obj's fields corresponding to that user id should be populated on the page.
All this info' is in extension to my question mentioned above.

I was planning to use vectors. Please do let me know if anyone has done anything similar to this.

-- Any help would be apreciated --
0
Comment
Question by:prashant_khanna
  • 26
  • 21
  • 4
54 Comments
 
LVL 7

Expert Comment

by:CajunBill
Comment Utility
Sounds like you need a bean, in order to communicate the objects between pages.
And it looks like you need some additional code, either JSP or Javascript, to control the tables.

Try posting some additional explanation of what you want, such as an example of an expanded row/table.
0
 

Author Comment

by:prashant_khanna
Comment Utility
It is not necessary for me to use 2 jsp's with an object in each of them. I could very well use a single jsp. I have already mentioned as to what i need to do above. But still if u need further explanation then its as follows:

 Every time a use clicks on the add button, a new table instances is shown on the screen below the previous table which was filled by the user. Something like a shopping cart. Like every time u add a new order, a new row representing the order is created. Here I need to add a new table(the fields in the table will be the same, but they will be empty thought) instead of a new row.

 Hope this helps.

 Thanx for ur quick reply.

 
0
 
LVL 7

Expert Comment

by:CajunBill
Comment Utility
(Hmmm ... strange reply.  One more time ...)

Prashant, you did not seem to like my asking for clarification, even though you've failed when asking the question before (see http://experts-exchange/Web/Q_21108363.html)

I'll sketch this out in JavaScript since you seem to want to avoid Java.
However, I'm sure you want the order objects to persist, so you will need to use a bean for that.

Anyway I will just sketch an answer here, if you want more details let me know:

<html>
<head>
<script language="javascript">
function delete_order(x)
{ ... }
function add_order()
{
order_name.push(newordername );
order_description.push(neworderdescription );
}
</script>
</head>
<body>
<script>
var order_name=new array(1);
var order_description=new array(1);

i=0;
while (order_name(i))
{
document.write("<tr> <td>");
document.write(i+1);
document.write("</td><td>");
document.write(order_name(i));
document.write("</td><td>");
document.write(order_description(i));
dorcument.write("</td><td><Input type=button value='delete order' onClick='delete_order(");
document.write(i);
document.write(")' /></td></tr>");
i++;
}
// Now display an empty row for the user to fill in if desired
</script>
<tr><td><input type="text" name="newordername" value="New Order Name" /></td>
<td><input type="text" name="neworderdescription" value="New Order Description" /></td>
<td><input type="button" value="Add New Order" onClick="add_order()" /></td>
</tr>
</body>
</html>

0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi!
I didn't mean to sound like trying avoid java code and I am prefectly fine with u asking me clarification. Hence let me explain exactly what this is about.

 I have jsp which contains a UI for the user to enter his/her information (lets say a user information part) and then I have 2 options:
 1. To have 2nd part in the jsp and this part is gonna be a dynamic one. Dynamic in the sense as follows:
     - The 2nd part is gonna be the part where the user enters part order information. This part is gonna be shown to the user as a HTML table containsing about 20 fields(checkbox, text,radio button).
 2. The second part can also be implemented as a seperate jsp page. After which i can include this page in my 1st page.

 But I prefer to stick with the 1st one. Hence now my final page will have 2 tables. One on the top half of the page and the other on the bottom half of the page. The 2nd table which is a dynamic one needs to have the following logic:
   - when I fill in the info in the second HTML table (part order info) and then if I want to add another part order, I would click on the add button on the page and on lcicking that I would be provided an exact clone of the 2nd table but with empty fields in it so that the user can fill in info for a new part order. While this is being done the top part of the table and the previous( part order info) table is still gonna be shown with all its fields still editable.
 I will send all the data from the page to the database only when the user clicks submit. Yes, u are right in the fact that I will need beans and I will be using that.
 Hence what I am planning is to create 2 vectors. One a dummy vector to create a new instance of the 2nd table when the user clicks on the add button and another vector to hold the values the user enters (I am sorry if I am not clear on this).

I would really appreciate if u could provide ur suggestions too. Do let me know if u need any further info. Thank u for ur reponse.
0
 

Author Comment

by:prashant_khanna
Comment Utility
The script and the html u send earlier doesn't work. Could u plz check it out.
0
 
LVL 7

Expert Comment

by:CajunBill
Comment Utility
OK, the old code just displayed the empty row.
This still is all javascript, no java beans, but it will illustrate controlling the table rows.
Because it is all script, no bean, it cannot actually add to the tables.
Try this and you will see that it displays whatever is loaded in to the arrays.

Next  we can work on making this really JSP and beans.
-----------
<html>
<head>
<script type="text/javascript">
function delete_order(x)
{
x=0;
//
}
function add_order()
{
order_name.push(newordername );
order_description.push(neworderdescription );
window.location.reload();
}
</script>
</head>
<body>
<table>
<script type="text/javascript">
var order_name=new Array("abc","def","GHF");
var order_description=new Array("123","345","456");

i=0;
while (order_name[i].length>0)
{
document.write("<tr> <td>");
document.write(i+1);
document.write("</td><td>");
document.write(order_name[i]);
document.write("</td><td>");
document.write(order_description[i]);
document.write("</td><td><Input type=button value='delete order' onClick='delete_order(");
document.write(i);
document.write(")' /></td></tr><br>");
i++;

}
// Now display an empty row for the user to fill in if desired
</script>
<tr><td><sp><sp><sp><sp></td>
<td><input type="text" name="newordername" value="New Order Name" /></td>
<td><input type="text" name="neworderdescription" value="New Order Description" /></td>
<td><input type="button" value="Add New Order" onClick="add_order()" /></td>
</tr>
</table>
</body>
</html>

0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi!
Thanx for ur prompt response. Yes it did show all tht is loaded into the array. Now about the part about making it a jsp and using beans along with it. So how do i go about doing that?

Thanx

 
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Mr. Khanna,
Has this question been answered? if not,
You can use only one JSP to do all the stuff, I am doing it in my projects. I try to avoid JavaScript in JSP, because it acts funky sometimes. Anyway, Use Servlet to acomplish what you want to do. Call the servlet from JSP anytime you want to do anything, like adding row or deleting row. And for that purpose you will need to set attributes and get attributes so that you don't loose information when you access servlet. Session beans is another option to serve this.
If you need more clarification on this please let me know.
--Raj
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Raj
If u could assist me with a sample code, it would help.

Thanx
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Here is a sample JSP;
++++++++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="GENERATOR" content="IBM WebSphere Studio" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="theme/Master.css" rel="stylesheet"
      type="text/css" />
<title>sample.jsp</title>
</head>
<body>
<%
String action="";
if(session.getAttribute("action")!=null){
action =(String) session.getAttribute("action");
}
Vector name= new Vector();
if(session.getAttribute("name")!=null){
name =(Vector) session.getAttribute("name");
}
%>
<form action=sample>
<table><tr>
<td>Last Name</td>
<td>First Name</td>
<td>Action</td>
</tr>
<tr>
<td><input type="text" name="LNAME" /></td>
<td><input type="text" name="FNAME" /></td>
<td><input type="submit" name="SUBMIT" value="ADD" /></td>
</tr>
<%for(int i=0;i<name.size();i++){%>
<tr>
<td><%=name.elementAt(i)%></td>
<td><%=name.elementAt(i)%></td>
<%i=i+1;%>
<td><input type="submit" name="SUBMIT" value="DELETE" /></td>
</tr>
<%}%>
</table></form>
</body>
</html>
+++++++++++++++++++++++++++++++

Can you write a servlet that will read the attributes from the form;
like
Vector name = new Vector();
String action="";
name.addElement((String) req.getParameter("LNAME"));
name.addElement((String) req.getParameter("FNAME"));
action = (String) req.getParameter("SUBMIT");
//** When submit is DELETE you remove the two elements from the vector depending on the index of the element
now set attributes;
ses.setAttribute("name", name);
ses.setAttribute("action", action);
// Now go back to the sample page
resp.sendRedirect("sample.jsp");

I hope you got the idea. I am kind of busy right now, I would have given you complete code.
Try to work on this, if need more help let me know
-Raj


0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Prashant,
Did you get it working? Let me know I will take out some time and write servlet to make it work.
--Raj
0
 

Author Comment

by:prashant_khanna
Comment Utility
Nope! Haven't yet got it working.  

Thanx for asking
0
 

Author Comment

by:prashant_khanna
Comment Utility
If time permits could u send me the code in detail?

0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
OK
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Raj

 I was expecting the code in detail from your side. I am still waiting on that. I possible please try to send it ASAP.

Thanx Bud
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
My bad, I am working on it and send you today.
--Raj
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Bill
Would be helpful if u could elaborate on the jsp & beans part. Need to work on it ASAP.

 Any help would be appreciated.

 Thanx Guys
0
 

Author Comment

by:prashant_khanna
Comment Utility
Thanx Raj. I am working on getting the table dynamic. As u have suggested in ur earlier code.

 
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Raj
 
I tried the following code given by u
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ page
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="GENERATOR" content="IBM WebSphere Studio" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="theme/Master.css" rel="stylesheet"
     type="text/css" />
<title>sample.jsp</title>
</head>
<body>
<%
String action="";
if(session.getAttribute("action")!=null){
action =(String) session.getAttribute("action");
}
Vector name= new Vector();
if(session.getAttribute("name")!=null){
name =(Vector) session.getAttribute("name");
}
%>
<form action=sample>
<table><tr>
<td>Last Name</td>
<td>First Name</td>
<td>Action</td>
</tr>
<tr>
<td><input type="text" name="LNAME" /></td>
<td><input type="text" name="FNAME" /></td>
<td><input type="submit" name="SUBMIT" value="ADD" /></td>
</tr>
<%for(int i=0;i<name.size();i++){%>
<tr>
<td><%=name.elementAt(i)%></td>
<td><%=name.elementAt(i)%></td>
<%i=i+1;%>
<td><input type="submit" name="SUBMIT" value="DELETE" /></td>
</tr>
<%}%>
</table></form>
</body>
</html>
But it doesn't seem to work. As in After entering values for FNAME & LNAME when I click on add, it doesn't show me the new added elements.
0
 

Author Comment

by:prashant_khanna
Comment Utility
Raj a quick recap:
1.
From what I see in ur code, everytime the user clicks add, the values get stored in vector and are displayed to the user. Now the user will not be able to edit these values if he wanted to. I actual want the user to be able to edit the values until and unless he click on the submit button.
I guess in that case I need to store the values into the vector then get the values from the vector and if changes are made I have to update the vector.

2.
Next, In ur code, u are having 2 textboxes only. Will this same logic work if I added an entire HTMl table containing various fields such as textboxes,radio buttons,dropdown list; instead of just 2 textboxes.

 If u noticed, I have increased the points value of this question by 100.

Need answers ASAP. Sorry I am pushing hard on this coz' I am sure u must be busy with ur work too.
But any help would appreciated.
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Here is the complete working code;

JSP file
+++++++++++++++++++++++
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ page
language="java"
import="java.util.*"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="GENERATOR" content="IBM WebSphere Studio" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="theme/Master.css" rel="stylesheet"
      type="text/css" />
<title>sample.jsp</title>
</head>
<body>
<%
String action="";
if(session.getAttribute("action")!=null){
action =(String) session.getAttribute("action");
}
Vector name= new Vector();
if(session.getAttribute("name")!=null){
name =(Vector) session.getAttribute("name");
}
session.setAttribute("name", name);
%>
<form action=sample>
<table><tr>
<td>Last Name</td>
<td>First Name</td>
<td>Action</td>
</tr>
<tr>
<td><input type="text" name="LNAME" /></td>
<td><input type="text" name="FNAME" /></td>
<td><input type="submit" name="SUBMIT" value="ADD" /></td>
</tr>
<%for(int i=0;i<name.size();i++){%>
<tr>
<td><%=name.elementAt(i)%></td>
<td><%=name.elementAt(i+1)%></td>
<%String index = "DEL"+Integer.toString(i);
i=i+1;%>
<td><input type="submit" name="SUBMIT" value="<%=index%>" /></td>
</tr>
<%}%>
</table></form>
</body>
</html>
++++++++++++++++++++++++++
Servlet
=======================
import java.io.IOException;
import java.util.Vector;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @version       1.0
 * @author      rsingh
 */
public class sample extends HttpServlet implements Servlet {

      /**
      * @see javax.servlet.http.HttpServlet#void (javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
      */
      public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
                  
                  HttpSession ses = req.getSession();                  
                  Vector name = new Vector();
                  name =(Vector) ses.getAttribute("name");
                  String action1 = (String) req.getParameter("SUBMIT");      
                  
                  String action = action1.substring(0,3);                  
                  if(action.equals("ADD")){
                        name.addElement((String) req.getParameter("LNAME"));
                        name.addElement((String) req.getParameter("FNAME"));
                  }
                  if(action.equals("DEL")){
                        int index =Integer.parseInt(action1.substring(3));                        
                        name.removeElementAt(index);
                        name.removeElementAt(index);                        
                  }
                  ses.setAttribute("name", name);
                  resp.sendRedirect("sample.jsp");
      
      }

}
======================

*******delete button is showing index values tith DEL, remember you can define hight and with of button with css to hide the number after DEL, or you can use an image. That will look better.
Let me know if you need help.
--Raj
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Khanna ji,
Answer to your questions;
1. See the code for delete option I am reading the index of the element. Now when you know the index of the element you can do whatever you want i.e. delete, edit,update more precisely. To edit all you need to do is overwrite the element with new value.
Question is how you allow user to change the value, simple, see the code we are just getting value from the vector and displaying it in <td></td>.
You can include input text field, use CSS to change the borders of text input field to look like table. now user can change the values in input box. But to make changes in effect they need to click on update button, which you will add after the row with Delete button.
Whole point is it's easy and doable.
2. You can use as many input boxes, checkboxes, select, and so on. Just keep on adding similar code, keep track of vector size. I used only two input boxes to give you an idea, and clarify things for you. You can modify it as par your need.
--Raj
0
 

Author Comment

by:prashant_khanna
Comment Utility
Sorry about the silly questions Raj Bhai.

 I will work on the code and keep u posted its status.

 Thanx

 
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Common, I am in learning process too. Noone is perfect. No question is silly, it's the people who think that, are silly, sorry didn't mean to offend you. Whole point is, you are welcome.
--Raj
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Khanna ji,
Did you get it working?
Use this for delete button.
<input type="submit" name="SUBMIT" value="<%=index%>" style="width:32px;background:orange;"/>
It shows the button only with DEL, looks more authentic.
Let me know if you need more help.
-Raj
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:prashant_khanna
Comment Utility
Working on it. Will let u know as soon as i get it going. Thanx
0
 
LVL 7

Expert Comment

by:CajunBill
Comment Utility
prashant, you may run into one or two issues.
However, raj has given you a lot of a big start in the right direction.

First, raj is apparently using IBM Websphere Studio.  If you are not using this then you may not have all the files this gives to him.  For example,  his code includes href="theme/Master.css" and you may not have this.

Second, I'm sure you want the data to persist.  So you will need to write it out somewhere, probably into a database.  That way, when the user closes the browser then comes back later, you can still present the same data.

Last, if you find that you are using multiple JSPs then you will still want to use a bean.  But let's not get into that unless you need it.
Regards, Cajun
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Issues Cajon has discussed are legitimate;
1. I am using IBM websphere, but  href="theme/Master.css" is not big deal Prashant can create one his own. I don't even use this one I have my own css file.
2. Prashant's problem at present is to get dynamic table, and we are trying to do that. Once he is done with that I am sure his next step would be to think about data storage.

So, Prashant how far are you on the project, did you get it working??
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Guys
Thanx Cajun about bring up those issues. I was aware of them. But really do appreciate u letting me know about them. Actually I will be working on this by friday or during this weekend since I am working on a major issue in my project. Will definetely keep u guys posted about it.

 Actually Raj if I get the dynamic table going that would be a good step ahead. Let me work on it ASAP and will let u know. Right now for the static part of the form, I am able to get info from the fields and store it in the database. Also I am able to get it out of the database. Also I was wondering if u guys had mail id i could reach u at during the weekend or maybe even a phone #, if u don't mind me asking that.

 Thanx again.
0
 

Author Comment

by:prashant_khanna
Comment Utility
u can reach me at pkhann1@gmail.com
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
singh@louisiana.edu
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Raj
I tried to use your code but it didn't work fine. The sample.java
compiled fine. I have attached the error file and the jsp. I didn't
make any changes to the .java, used it as it was and placed it under
the WEB-INF\classes directory in my weblogic (using weblogic 8.1).

I get the following error on clicking add:

Line:       65
Char:       26
Error:       Object expected
Code:       0
URL:       

http://taipei.savvion.com:18793/sbm/BizSolo/addtable/Activity_1.jsp?LNAME=reg&FNAME=miller&SUBMIT=ADD&crtApp=addtable&crtPage=Activity_1&activityMode=procReq&nextPage=Start.jsp

My JSP file is

<%@page import="java.util.Vector" contentType="text/html;charset=UTF-8" %>

<%! String _PageName = "Activity_1"; %>
<%! String __webAppName = "addtable"; %>

<!-- begin head-->
<%! int res=-10; %><html>
<head>
<title><%=_PageName%></title>
<META HTTP-EQUIV='CONTENT-Type' CONTENT='text/html;charset=UTF-8'> </META>
<bizsolo:link rel="stylesheet"/>
</head>
<body BGCOLOR="#FFFFFF">

<!-- end html head -->



<form method="post" name="form" onSubmit="action='<%=response.encodeURL("Start.jsp")%>'; return validate();">
<%
String action2="";
if(session.getAttribute("action2")!=null){
action2 =(String) session.getAttribute("action2");
}
Vector name= new Vector();
if(session.getAttribute("name")!=null){
name =(Vector) session.getAttribute("name");
}
session.setAttribute("name", name);
%>
  <table>
    <tr>
      <td>Last Name</td>
      <td>First Name</td>
      <td>Action</td>
    </tr>
    <tr>
      <td><input type="text" name="LNAME"/></td>
      <td><input type="text" name="FNAME"/></td>
      <td><input type="submit" name="SUBMIT" value="ADD" ONCLICK='clickedButton=this.name;'/></td>
    </tr>
    <%for(int i=0;i<name.size();i++){%>
    <tr>
      <td>
        <%=name.elementAt(i)%>
      </td>
      <td>
        <%=name.elementAt(i+1)%>
      </td>
      <%String index = "DEL"+Integer.toString(i);
i=i+1;%>
      <td><input type="submit" name="SUBMIT" value="<%=index%>"/></td>
    </tr>
    <%}%>
  </table>
  <p>
    <input type=hidden name="crtApp" value="addtable">
    <input type=hidden name="crtPage" value="Activity_1">
    <input type=hidden name="activityMode" value="procReq">
    <input type=hidden name="nextPage" value="<%=response.encodeUrl("Start.jsp") %>">
  </p>
 

<table border=0 class="ApSegDataTbl">
<tr>
<td><input type=submit name="SB_Name" value="Submit" ONCLICK='clickedButton=this.name;'></td>


</tr>

</table>
</form>
<br>

<!-- begin html body-->


<!--end html body-->

<!--begin html tail------>
</body>
</html>
<!--end  html tail---->





0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Did you try using the code I posted, before changing the JSP. Try to use the JSP I have posted, it should work because I tested it. Once it works then let me know I will tell you what you are doing wrong in your JSP.
--Raj
0
 

Author Comment

by:prashant_khanna
Comment Utility
It gives me the same error
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Raj
I think I am making a mistake in my my form post method or maybe its beacuse of improperly reference to the method in my sample.java class.
If u could help me on that. Also check this link
http://www.experts-exchange.com/Web/Web_Languages/XML/Q_20623429.html


0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
My code should work, use my code as it is i.e. JSP and servlet, you are doing some mistake in your JSP when you make changes, you should, leave this line as it is;
<form action=sample>

and then all the actions of your form will be handled by servlet. so when you use something like this:
<input type=submit name="SB_Name" value="Submit" ONCLICK='clickedButton=this.name;'>

gives you error.
Try to make the code I gave you make work, when I say, make it work means use that code as it is do not make any changes to that code, and see if it works, you should be able to add names and then delete.
Once that works then I will tell you how to handle your stuff.
-Raj
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Another thing your sample.java does not go to WEB-INF\classes folder, that is the folder for all classes created from all java files you have. Anyway I do not know how web logic does it, but I have a folder name Java Source created by websphere all my java files go there, and all I do is just call it from my JSP, and websphere keeps all classes in  WEB-INF folder. If you want you should put sample.class in  WEB-INF\classes folder. If you are having problems with servlet we can use JSP to do the same stuff.
Let me know if you need help on that.
-Raj
0
 

Author Comment

by:prashant_khanna
Comment Utility
used ur code as it is. It gives me an error 404 everytime i click on add. Moreover it doe not display the index button.

0
 

Author Comment

by:prashant_khanna
Comment Utility
The exact error message that I am geeting on clicking add:

Error 404--Not Found
From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1:
10.4.5 404 Not Found
The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent.

If the server does not wish to make this information available to the client, the status code 403 (Forbidden) can be used instead. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address.
 

0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Hmmm,
I don't know what that is, never worked on weblogic, anyway, I will send you servlet converted to JSP, that must work.
Take care
0
 

Author Comment

by:prashant_khanna
Comment Utility
gr8. Thanx Raj. Sorry for all the trouble.
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi Raj

Didn't hear from you. Was wondering if you could help me out with  sending the JSP.

Thanx in advance
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Sorry bud,
I have been busy for last three days, I have been working on projects and was trying to trade my car with another and get some cash money, state Job does not pay you much to have a good life.
Anyway I will be posting something in a few.
-Raj
0
 
LVL 11

Accepted Solution

by:
raj3060 earned 350 total points
Comment Utility
Prashant here is the working code:

**sample.jsp
=========================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ page
language="java"
import="java.util.*"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="GENERATOR" content="IBM WebSphere Studio" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="theme/Master.css" rel="stylesheet"
      type="text/css" />
<title>sample.jsp</title>
</head>
<body>
<%
String action="";
if(session.getAttribute("action")!=null){
action =(String) session.getAttribute("action");
}
Vector name= new Vector();
if(session.getAttribute("name")!=null){
name =(Vector) session.getAttribute("name");
}
session.setAttribute("name", name);
%>
<form action=sampleservlet.jsp>
<table><tr>
<td>Last Name</td>
<td>First Name</td>
<td>Action</td>
</tr>
<tr>
<td><input type="text" name="LNAME" /></td>
<td><input type="text" name="FNAME" /></td>
<td><input type="submit" name="SUBMIT" value="ADD" /></td>
</tr>
<%for(int i=0;i<name.size();i++){%>
<tr>
<td><%=name.elementAt(i)%></td>
<td><%=name.elementAt(i+1)%></td>
<%String index = "DEL"+Integer.toString(i);
i=i+1;%>
<td><input type="submit" name="SUBMIT" value="<%=index%>" style="width:32px;background:orange;"/></td>
</tr>
<%}%>
</table></form>
</body>
</html>
======================================

**
+++++++++++++++++++++++++++++++++
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ page
language="java"
import="java.io.IOException"
import="java.util.Vector"
import="javax.servlet.Servlet"
import="javax.servlet.ServletException"
import="javax.servlet.http.HttpServlet"
import="javax.servlet.http.HttpServletRequest"
import="javax.servlet.http.HttpServletResponse"
import="javax.servlet.http.HttpSession"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="GENERATOR" content="IBM WebSphere Studio" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link href="theme/Master.css" rel="stylesheet"
      type="text/css" />
<title>sampleservlet.jsp</title>
</head>
<body>
<%
                  
                  Vector name = new Vector();
                  name =(Vector) session.getAttribute("name");
                  String action1 = (String) request.getParameter("SUBMIT");      
                  
                  String action = action1.substring(0,3);                  
                  if(action.equals("ADD")){
                        name.addElement((String) request.getParameter("LNAME"));
                        name.addElement((String) request.getParameter("FNAME"));
                  }
                  if(action.equals("DEL")){
                        int index =Integer.parseInt(action1.substring(3));                        
                        name.removeElementAt(index);
                        name.removeElementAt(index);                        
                  }
                  session.setAttribute("name", name);
                  response.sendRedirect("sample.jsp");
      
%>
</body>
</html>
++++++++++++++++++++++++++++++++++

put both jsp in some folder, it should work..
Let me know the result.
-Raj
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Khanna ji,
No comments??
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Mr. Khanna,
It's been long you did not reply. If this question is answered then close it.
Thanks
0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi
I am testing out the code you gave me (today). You would get a comment by this evening. Sorry for the delay.




0
 

Author Comment

by:prashant_khanna
Comment Utility
Hi

When I click on the add button, after the table adds to the page the rest of the data in various other fields (not related to the part order table) get refreshed. As all the values in texteboxes, selection etc are reset back to null. How do i prevent this ?

 please reply asap.

0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
You need to read all the values null or anything you entered, save everything in array or vector, and retreive back when you come back to the page. It will be very similar to what we did before.
-Raj
0
 

Author Comment

by:prashant_khanna
Comment Utility
Don't worry about it I fixed.
Thanx thought.
0
 
LVL 11

Expert Comment

by:raj3060
Comment Utility
Pinal,
I have already answered the question and given solution for what the original question was. Prashant is having trouble with some stuff. If you want to close, I should get the points.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This video teaches users how to migrate an existing Wordpress website to a new domain.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now