Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:27:35+00:00 2026-06-13T20:27:35+00:00

My jquery is: $(‘select[name=select1]’).change(function () { var cod=$(this).val(); if (cod>0) { $.ajax({ url:Load.do, data:

  • 0

My jquery is:

$('select[name=select1]').change(function () {
            var cod=$(this).val();
            if (cod>0) {
                $.ajax({
                    url:"Load.do",
                    data: "cod="+cod,
                    success: function (response) {
                            $('#info').html(response); }
                    });
            }
        });

In the struts-config.xml, I have:

<action path="/Load" scope="request" type="mypackage.Load"></action>

The class Load is an Action:

public class Load extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
{
    // TODO Auto-generated method stub

    Connection con = null;
    Statement stmt = null;
    ResultSet rs = null;

    try {
        // get the connection 
        stmt = (Statement) con.createStatement();

        String cod = request.getParameter("cod");

        String select = new String("Select firstCode, name from mytable where secondCode = '");
        select = select.concat(cod);
        select = select.concat("';");
        rs = stmt.executeQuery(select);
        PrintWriter out = response.getWriter();
        while (rs.next()) {
            out.print("<html:option value='");
            out.print(rs.getString("firstCode"));
            out.print("'>");
            out.print(rs.getString("name"));
            out.println("</html:option>");
            out.flush();
        }

        return null;
    } catch (NamingException e) {
        e.printStackTrace();
    } catch (SQLException e) {
        e.printStackTrace();
    }  catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (rs != null) {
              try { rs.close(); } catch (SQLException e) {}
              rs = null;
        }
        if (stmt != null) {
              try { stmt.close(); } catch (SQLException e) {}
              stmt = null;
        }
        if (con != null) {
              try { con.close(); } catch (SQLException e) {}
              con = null;
        }        
    }

    return null;
}
 }

The data are retrieved, but they aren’t printed in the info div.

In my .jsp page, the select which I want fill is:

 <html:select property="prop1">
 <html:option value="0">Choose:</html:option>
 <div id="info"></div> 
 </html:select>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:27:36+00:00Added an answer on June 13, 2026 at 8:27 pm

    The JSP code is not really relevant. What matters is the generated HTML code. Use Firebug or a similar tool to inspect the contents of your page, and see what the problem is. If the Struts action returned the appropriate HTML, like the following:

    <option value="2">some label</option>
    <option value="3">some other label</option>
    

    then the above Javascript would replace the contents of the div identified by info with the above HTML. So the end result would be

    <select name="prop1">
        <option value="0">Choose:</option>
        <div id="info">
            <option value="2">some label</option>
            <option value="3">some other label</option>
        </div>
    </select>
    

    And the above is invalid HTML. The options shouldn’t be inside a div, but directly under the select element.

    Give the select element an ID, and replace the contents of the select element by the response of your AJAX request.

    But the other problem is that your action doesn’t generate HTML code, but JSP code containing Struts tags. This makes no sense. Struts tags are interpreted by a JSP, at server-side. But you’re sending them directly to the browser. The browser only understands HTML. It doesn’t know about Struts tags.

    Why aren’t you using the recommended MVC approach? The action should generate a list of beans, store it in the request, and forward to a JSP which would generate the HTML markup using tags.

    Finally, you should

    • use prepared statements rather than String concatenation
    • HTML-escape your Strings. The Struts tags do that for you
    • avoid swallowing exceptions
    • not end the SQL query with a semi-colon.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Jquery did not carry out!!!I don't know why $(.other-edithion).click(function(){ var city = $(this).closest('#city'); if
jQuery code: function ajaxsubmit(){ $.ajax({ url: /update, type: POST, dataType: html }).success(function(data) { $('#result').html(data);
jQuery(document).ready(function($) { $('input[type="text"]').live('focus', function() { if (this.value == 'someValue') { this.select(); } }); });
jQuery(document).ready(function($) { var devices = $(.menu-item-custom).map(function() { return this.id.substr(10); }).toArray(); $.each(devices, function() { $(#menu-item-settings-+this+
JQUERY <script type=text/javascript src=jquery-1.5.1.min.js></script> <script type=text/javascript> $('#aggiungi').live('click', function(){ var thisRow = $(this).parent().parent(); // clone
jQuery(function ($) { $('input.adud').on('click', function() { var thisdiv = $(this).parents('div').attr(id); var thisform = $(this).parents('form').attr(id);
jQuery('td[class=bgoff]').each(function() { var td = jQuery(this); ... no apply selector to this only });
jQuery Code : (function($){ $.fn.jgtextdefault = function(settings){ var jElements = this; var settings =
jquery looks like this $.post('JSP/processForm.jsp', $(#Form).serialize(), function(data){ //I want to iterate through every line
jQuery.widget(ui.test,{ _init: function(){ $(this.element).click(this.showPoint); }, showPoint: function(E){ E.stopPropagation(); alert(this.options.dir); } } $('#someEleme').test(); Right now,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.