Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default form and results on same page using servlets

    i have jsp form which sends values to the mysql database and a servlet then displays all the values from the database. how do i go about comibining the into one form? any tutorial or advice will be welcomed

  2. #2
    KeyCode is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default

    Java Code:
    [U]SaveToDB.jsp[/U]
        <form method='post' action='SaveToDB.jsp'>
          <input type='text' name='name'/>
          <input type='submit' name='Submit'  value='Send'/>
        </form>
    <%
    String name  = request.getParameter("name");
    if(name!=null) { enterIntoDB(name); }
    %>
       <%= valueFromDB() %>
    		
    		<%!
    		  static public String valueFromDB() {
    		    String values = {code for retreiving name from DB }
    		    return values;    
    		  }
    		  static public String enterIntoDB(String name) {
    		    {code for entering name into DB }
    		    return values;    
    		  }
    		%>

  3. #3
    Join Date
    Mar 2008
    Posts
    25
    Rep Power
    0

    Default

    so i see the form method sends it to same .jsp page and the request.getParam picks it back up and
    sends to db if not null, then calls the method to retrieve it...thanks, i'll try this out

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    6

    Default

    what keycode says is generally the behavior you want: if form is submitted, do one task. if form isn't submitted, do another task.

    however, i think that it's better practice to have jsp's only outputting information. forms should post to servlets (not jsp's), which should process information and forward to the jsp for whatever the user sees. just my opinion though

Similar Threads

  1. how to connect form to another form in netbeans5.5
    By Shivraj in forum AWT / Swing
    Replies: 1
    Last Post: 03-17-2009, 09:01 AM
  2. Replies: 6
    Last Post: 11-28-2008, 06:55 AM
  3. how to take query results to a jlist!!
    By themburu in forum JDBC
    Replies: 1
    Last Post: 06-07-2008, 10:51 AM
  4. how to take query results to a jlist!!
    By themburu in forum New To Java
    Replies: 3
    Last Post: 06-07-2008, 10:45 AM
  5. 1 form 2 servlets
    By sandor in forum Java Servlet
    Replies: 2
    Last Post: 01-22-2008, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •