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 6680901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:31:44+00:00 2026-05-26T04:31:44+00:00

I’m working on a JSF 2.0 web app, and I’m having trouble passing in

  • 0

I’m working on a JSF 2.0 web app, and I’m having trouble passing in a String composed of different words separated by a ‘|’ to jQuery’s AutoComplete using a servlet. It works great in IE, but seems to fail retrieving any data in Firefox.

My XHTML file is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<ui:composition template="/WEB-INF/templates/base.xhtml">

    <ui:define name="head">

        <script>
        $(document).ready(function(){

                //var availableTags = "yes|maybe|no".split('|');

                $.ajax({
                    type:   'POST',
                    cache:  'false',
                    data:   'codeType=allergyList',
                    url:    '/miloWeb/Autocomplete',
                    async:  false,
                    success: function(data){
                        availableTags = data.split('|');    
                    },
                    error: function (xhr, ajaxOptions, thrownError){
                        alert(ajaxOptions);
                    }   
                });

                $("#pAllergy").autocomplete({
                    source: availableTags
                });

            });

        </script>
    </ui:define>    

<ui:define name="content">

        <h2>Allergy List</h2>
        <div>
        <center>
            <br />
            <br />
                <h:outputText styleClass="description" for="pAllergy">Allergy: </h:outputText>  
<h:inputText id="pAllergy" value="#{allergyListBB.allergyList.allergy}" size="30"></h:inputText>

                </tr>
                <tr>
                    <td><button onclick="return false;" id="addAllergy">Add</button> </td>                      
                </tr>
            </table>
        </center>
        <h:inputHidden id="delId" value="#{allergyListBB.rowId}"></h:inputHidden>
        </div>

</ui:define>

What this last part of code is doing is going into my Servlet and retrieving from the DB a string (i.e. cheese|chocolate|chery|chestnut| ) which then goes into the variable availableTags which is what we pass into the autocomplete.

My servlet looks like this:

package com.bravo.servlets;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bravo.codeMaster.codeMaster;
import com.bravo.dropdowns.codeMedicationList;

/**
 * Servlet implementation class Autocomplete
 */
@WebServlet("/Autocomplete")
public class Autocomplete extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Autocomplete() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getOutputStream().print("Unauthorized Access.");
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        String codeType = request.getParameter("codeType");
        response.getOutputStream().print(codeMaster.getStringList(codeType));
        // This might as well be "response.getOutputStream().print("one|two|three|")
        // for testing purposes, just to make sure it's returning something.
    }

}

XTRA COMMENTS: It seems to me that if I set the variable availableTags to any string of strings, the moment I set the $(“#pAllergy”).autocomplete(), I can’t change it. so I need to get the correct string from the Servlet. Please help me out I can’t seem to figure out why it fails in Firefox and not in IE. I greatly appreciate the help!

  • 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-05-26T04:31:45+00:00Added an answer on May 26, 2026 at 4:31 am

    You forgot to set the HTTP Content-Type response header in the servlet. Assuming that it’s text/plain, you need to add the following line before you write any bit to the response:

    response.setContentType("text/plain");
    

    This way jQuery can do its “intelligent guess” properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
We're building an app, our first using Rails 3, and we're having to build
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace

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.