• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

code Help

hi experts,

I have a JSP which has multiple text boxes...

<input type="text" name="teacher_comment_<%=StudentID%>" size="40">

What I want in my servlet is when the box is empty ignore it, otherwise get 'StudentID' and update DB.

Currently my servlet has this code: Now how to add the above requirment in this below code:

while (allnames.hasMoreElements())
        {              
            String name = (String)allnames.nextElement();        
            if (name.startsWith("School"))
            {
               String ObjName = (String)request.getParameter(name);
               String lineno = name.substring(5);
               ClassXYZ ac = (ClassXYZ) session.getAttribute(ObjName);
               String[] records_seq =ac.getPendingSeqs(",").split(",");
               for (int i=0; i<records_seq.length; i++)
               {
             // Do DB ...
        }...


Thanks,
PH
0
princehyderabad
Asked:
princehyderabad
1 Solution
 
Jim CakalicSenior Developer/ArchitectCommented:
Perhaps something like:

    if (name.startsWith("teacher_comment")) {
        String value = request.getParameter(name);
        if (value != null && value.trim().length() > 0) {
            String[] parts = name.split("_");
            String studentId = parts[2];
            ... do you update
        }
    }
       
Regards,
Jim
0
 
rrzCommented:
jim cakalic, did you see my message to you at
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21828189.html     

princehyderabad, I am sorry for intruding here. You  are in jim's capable hands.
0
 
princehyderabadAuthor Commented:
U mean ..

String studentId = parts[2];
 for (int i=0; i<parts.length; i++)
               {
             // Do My updates
             }
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Jim CakalicSenior Developer/ArchitectCommented:
Well,

    String[] parts = name.split("_")

will give you a String[] with the contents:
    parts[0] == "teacher"
    parts[1] == "comments"
    parts[2] == <the embedded studentId>

the actual value of the text input with the name "teacher_comments_<the studentId>" were retrieved with:
    String value = request.getParameter(name);

So the value variable has whatever comments were typed in the text field. The studentId variable has the embedded student id value. Not sure how your database update looks but that is two of the values you are likely going to want to use for some subsequent update/insert.

Jim
0
 
CEHJCommented:
>>What I want in my servlet is when the box is empty ignore it

Do you mean when the below 'ObjName' is empty?

>>String ObjName = (String)request.getParameter(name);

If so,

if (ObjName == null || (ObjName = ObjName.trim()).length() < 1) {
    continue;
}

should be OK if i've interpreted your code correctly
0
 
princehyderabadAuthor Commented:
Well let me example my need once more clearly:

JSP displays 100's of records when user selects 'Accept' on particular record and submit,  line_no mentioning whether record is 'accepted', 'rejected', or did'nt selected (empty) and seqs_line_no containing a session object name is passed. In that sesssion is the ID number of student. See eg. belwo

So Basically JSP passes name, values pair and session ID containg ID number:

seqs_line_1,ID_line_1
seqs_line_2,ID_line_2
seqs_line_3,ID_line_3
line_1, accept
line_2, reject
line_3, null


eg:
String SID= ID_line_1
session.setAttribute(SID, 303);

And Java code is:
..
while (allnames.hasMoreElements())
        {
        if (name.startsWith("seqs"))
            {
                   String ObjName = (String)request.getParameter(name);
               Approval aqc = (Approval) session.getAttribute(ObjName);              
               String[] records_seq =aqc.getPendingSeqs(",").split(",");
              for (int i=0; i<records_seq.length; i++)
               {
                     // Did DB changes
              }
           }
        }
         
EVERYTHING WORKS FINE. NOW COMES THE NEW REQUIREMENT WHERE COMMENT IS ASSOCIATED WITH EACH RECORD WHICH IS ALSO NEED TO BE RECORDED IN DB.

and JSP passes values like this now:

seqs_line_1,ID_line_1
line_1, accept
accept_comment_line_1,Student passed

eg:
String SID= ID_line_1
session.setAttribute(SID, 303);


So bascially I need to modify above code to or add a patch above or below my orginial code to add this comment stuff.

Thanks for your help.
PH
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now