top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Passing input from jsp to action class

+2 votes

In my front end, i am allowing user to create and save multiple number of entries to a table at the same time.

For now i am sending this input to Java class in form of string which i am creating at the time of save. But if table size is very very big(eg. 400-500 entries), then creating string is a time taking process.
Is the any other solution for this?

posted Oct 1, 2013 by Satyabrata Mahapatra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
I'm not sure what you mean "in form of string" - anything in http world is a string. When you posting a form with first name, last name and age, and birthdate - all these values are passed as strings. They can be converted to proper type on server side - automatically by a framework or manually by a developer.
try writing in to a file and passing that file, but it definately will be a bad practice if you 're planning less no of entries.
It means i am adding my all input values to a single string separated by some delimiter. And Split the string in my Class file to get those values.
For example,
|x1 | x2 | x3 | x4 |
|y1 | y2 | y3 | y4 |
|z1 | z2 | z3 | z4 |
var strStr = "x1val||x2val||x3val||x4val||y1val||y2val||y3val||y4val||z1val||z2val||z3val||z4val"
And i am setting this value into a hidden string.

1 Answer

+1 vote

Send them as a List.

In Action:    
private List<String> myList;    

In JSP, handle a counter, and each time the user create a new row, use it to index the row:

<input type="text" name="myList[0]" />
<input type="text" name="myList[1]" />
<input type="text" name="myList[2]" />

and next time the user will create an entry, it will be

<input type="text" name="myList[3]" />

If the user creates the entries from, let's say, a popup or a modal dialog, and they won't be editable after having been created, then generate an field along with a (or whatever):

<input type="hidden" name="myList[3]" value="lastValueEnteredByUser" />
answer Oct 1, 2013 by anonymous
An example or any link to go through will help a lot.
Similar Questions
+1 vote

May I know how to read a parameter value in JSP page for the following situation please?

... String list_size = list.size(); ...
getter/setter for list_size

(2) result.jsp

Is there a simple way to assign Struts2Action.list_size to s:select.size filed in the result.jsp file?

+1 vote

I have a table in Mysql DB like following

mysql> describe APPTBL;
| Field       | Type        | Null | Key | Default | Extra          |
| APP_ID      | int(11)     | NO   | PRI | NULL    | auto_increment |
| CREATE_DATE | date        | YES  |     | NULL    |                |
| CLOSE_DATE  | date        | YES  |     | NULL    |                |
| ACTION      | text        | YES  |     | NULL    |                |

While Starting of App, i am inserting the app details with CREATE_DATE and when it is closing, i am updating its CLOSE_DATE. But in case if user is restarting the app, i want to update NULL in place of CLOSE_DATE column. Here is my query,

mysql> update APPTBL set CLOSE_DATE = NULL where APP_ID = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0
mysql> select * from APPTBL ;
|    1      |  2013-10-08 | NULL       | XXXXXYYYYY |
1 row in set (0.00 sec)

But why i am not getting any result in this??

mysql> select * from APPTBL where CLOSE_DATE = NULL;
Empty set (0.00 sec)

Also, as i am writhing a java program using this where

rs = st.executeQuery("update APPTBL set CLOSE_DATE = NULL where APP_ID = 1");
   // Why it is coming here??
+1 vote

I need to integrate struts 2 with my classic web application based on servlet.

How do I tell struts 2 intercept only requests coming from specific folder like where I will placing all struts related source files?

Here is the link what I started at stackoverflow,

Please see if someone can throw some light on my issue.

+1 vote

We have an application wherein we want to keep separate database for each client. We want to achieve this using multi tenancy approach. A working example will be highly appreciated.