[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1112
  • Last Modified:

Trying to call my stringbuffer class in my JSP.

I'm trying to call a class (using StringBuffer for the html) in my jsp but can't seem to get the form objects (textbox, listmenu, checkbox) to display on the jsp.  I can display the text on the form (the form questions) the questions are coming from the database but not the html tags (form objects, table tags, etc).  The jsp is listed below.  Keep in mind the StringBuffer has all the html so that's why the jsp doesn't have html tags.

<%@page import="servlet.FormServlet"%>

     
     
   <%
      List Formquest = (List)request.getAttribute("Formquest ");
      Iterator it = Formquest.iterator();
      FormQuestions formInfo = null;
      String fquestion;
      String fobject;
      while (it.hasNext())
             {
               formInfo = (FormQuestions)it.next();
               fquestion = formInfo.getFormquest();
               fobject = formInfo.getType();
    %>
                <%= fquestion  %><BR><BR>
           <%= fobject %><BR><BR>

       <%
 
       if (fobject.equals("textfield")){
       %>
          <input name="<%= question %>" type="text">
         
       <%
       }
       if (fobject.equals("textarea ")){
       %>
         
       <%
       }
   
       if (fobject.equals("dropdown ")){
       %>
         
       <%
    }
   
 
   
    %>
 
   
 <%
   }
   %>
   
0
javabeginr
Asked:
javabeginr
  • 3
  • 2
  • 2
  • +1
1 Solution
 
objectsCommented:
whats the value of fobject?
0
 
patbinCommented:
first check that ur resulset is ok if it is ok then try this

<%@page import="servlet.FormServlet"%>

     
     
   <%
     List Formquest = (List)request.getAttribute("Formquest ");
     Iterator it = Formquest.iterator();
     FormQuestions formInfo = null;
     String fquestion;
     String fobject;
     while (it.hasNext())
             {
               formInfo = (FormQuestions)it.next();
               fquestion = formInfo.getFormquest();
               fobject = formInfo.getType();
    %>
               <%= fquestion  %><BR><BR>
          <%= fobject %><BR><BR>

       <%
 
       if (fobject.equals("textfield")){
     
      out.println("<input name=' question ' type='text'>);
       
             }
       if (fobject.equals("textarea ")){
similarly here also      
 }
   
       if (fobject.equals("dropdown ")){
       %>
         
       <%
    }
   
 
   
    %>
 
   
 <%
   }
   %>
hope this will solve ur problem
0
 
javabeginrAuthor Commented:
Nope doesn't work.  

Objects - the value of fobject is the form objects textfield, textarea, and menu/list.  

Can somebody please give me a solution?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
searlasCommented:
You need to show more of your JSP.  You mentioned something about StringBuffer, but there's no StringBuffer in the code you provide.

Also, it looks like you declare a variable called 'fquestion', but you also use 'question' in your scriptlet:
<input name="<%= question %>" type="text">

Where's this 'question' variable defined?

Show us the whole JSP and give us a chance to show you a solution.

0
 
javabeginrAuthor Commented:
Sorry but I'm not sure how to explain what I'm trying to do to you guys.  I mean I'm trying to build dynamic forms.  What I mean by this is I want to display the html tags dynamically from the servlet.  I have the string buffer on my servlet but I'm not sure how to call it to display the tags on my jsp.  The question variable is defined in the servlet (I changed it to object1 it makes more sense).  I'm displaying the questions from my database but not able to display the html form objects from my servlet using a stringbuffer.  My question is what am I doing wrong in my jsp why isn't the form objects showing? How do I call the stringbuffer to display the form objects?

<%@page import="servlet.FormServlet"%>

     
     
   <%
     List Formquest = (List)request.getAttribute("Formquest ");
     Iterator it = Formquest.iterator();
     FormQuestions formInfo = null;
     String fquestion;
     String fobject;
     while (it.hasNext())
             {
               formInfo = (FormQuestions)it.next();
               fquestion = formInfo.getFormquest();
               fobject = formInfo.getType();
    %>
               <%= fquestion  %><BR><BR>
          <%= fobject %><BR><BR>

       <%
 
       if (fobject.equals("textfield")){
       %>
          <input name="<%= object1 %>" type="text">
         
       <%
       }
     
   
    %>
 
   
 <%
   }
   %>




0
 
javabeginrAuthor Commented:
Also this is all of the jsp because again I'm trying to bring in the html tags dynamically from the servlet.  
0
 
objectsCommented:
Can you post the generated html please
0
 
patbinCommented:
can u paste some part of ur servlet
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now