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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:59:48+00:00 2026-06-14T00:59:48+00:00

I am new here and have been working on this all evening. I know

  • 0

I am new here and have been working on this all evening. I know this should be simple and I am just missing something silly. I have a jsp page and a servlet (code below). I am trying to search out a customer from my database, which works. However, if the customer is not found I want to post an error message on the same jsp page so that the user can possibly re-enter the phone number in case they made a mistake. I am unsure how to do this. I can forward to the new “customer” page just fine and I have tried successfully to redirect back to the same page, but I don’t know how to put the message there. Help please!

jsp page:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" isELIgnored="false" %>
    <%@ page import="java.util.*" %>  
    <%@ include file="staticpages/pageHeader.html" %>
        <br />      
            <hr />
            <br />
            <form name="custform" method="POST" action="ChooseCustomer.do" >
            <span class="sectionheader">Look Up Customer by Phone Number:</span>

            <input type="text" name="phone1" size="3" maxlength="3" onKeyUp="checklen(this)" />             
            <input type="text" name="phone2" size="3" maxlength="3" onKeyUp="checklen(this)" />
            <input type="text" name="phone3" size="4" maxlength="4" onKeyUp="checklen(this)" />
            <input type="submit" name="formaction" value="Search" />
            <input type="submit" name="formaction" value="Enter New Customer" />
            </form> 
    <%@ include file="staticpages/pageFooter.html" %>

servlet code:

package pizzapkg;

import java.io.IOException;
import java.sql.ResultSet;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

    /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)  */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Customer c = null;
        if (request.getParameter("formaction").equals("Search")) {

                Database db = (Database) getServletContext().getAttribute("db");
            /* Search Database for existing customer */
            String searchPhone = request.getParameter("phone1") 
                    + request.getParameter("phone2") 
                    + request.getParameter("phone3");
            String sql = "SELECT * FROM customers WHERE cust_phone=\"" + searchPhone + "\";";
            ResultSet rs;
            try {
                rs = db.runSqlQuery(sql);
                rs.next();
                c = new Customer(rs.getString("cust_id"), rs.getString("cust_fname"), 
                        rs.getString("cust_lname"), rs.getString("cust_address"), 
                        rs.getString("cust_city"), rs.getString("cust_state"), 
                        rs.getString("cust_zip"), rs.getString("cust_phone"),
                        rs.getString("cust_notes"));
            } catch (Exception e) { e.printStackTrace(); }
            request.setAttribute("customer", c);        
        }
        RequestDispatcher rd = request.getRequestDispatcher("/customer.jsp");
        rd.forward(request, response);
    }
}

PS This the the first time I have built a servlet so this is all new to me. I love examples so any help you can give will be greatly appreciated.

  • 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-14T00:59:50+00:00Added an answer on June 14, 2026 at 12:59 am

    You may set a flag in request object inside your servlet, if the customer is not found e.g.

              request.setAttribute("customerFound", "No");
    

    In your JSP, put a JSP scriptlet to check the request attribute and print the message wherever you want e.g. if you want the message after your <HR/> then:

            <hr />
            <% if("No".equals(request.getAttribute("customerFound")) { %>
                <div style="color: red">No customer found</div>
            <% } %>
            <br />
    

    I am sharing the very basic way of achieving your desired result.

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

Sidebar

Related Questions

All. I have been working on this for some time and can't seem to
I have been working on this all day, much of my code is from
I have a page that i have been starting to setup here http://www.brandybrowauto.com/NEW.html that
I have been working with this for a whole day but i cannot find
I have been working on a new installation of a Zend Framework application for
I'm fairly new to programming in general but have been working with Java for
I am relatively new to rails and have been working my way through the
Rails and all my gem files + homebrew installs have been working fine up
I have been working on this issue for a few days now and can't
First let me say that I have been working on this issue for about

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.