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
princehyderabadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.