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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:22:21+00:00 2026-05-20T08:22:21+00:00

Part of my homework for tomorrow is to search and add entries using Java

  • 0

Part of my homework for tomorrow is to search and add entries using Java EE. If the search is not existing, an add item option will show as follow:

Supposedly, when the Stock ID is not existing, It will be transfered to the Add Item Text Field of StockID. But I have no idea how to do it. My code is as follows:

Servlet:

public void doGet(HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        Item item = (Item) request.getAttribute("invenItem");
        if (item != null) {
            out.println("<html><title>Inventory Item</title>");
            out.println("<body><h1>Inventory Item Details:</h1>");
            out.println("Stock ID  : " + item.getStockID() + "<br/>");
            out.println("Name      : " + item.getItemName() + "<br/>");
            out.println("Unit Price: " + item.getUnitPrice() + "<br/>");
            out.println("On Stock  : " + item.getOnStock() + "<br/>");
            out.println("</body>");
            out.println("</html>");
        } else {
            RequestDispatcher rd = request.getRequestDispatcher("/DataForm.html");
            rd.include(request, response);
            out.println("Sorry Item not found..");
            rd = request.getRequestDispatcher("AddEntry.html");
            rd.include(request, response);
        }
    }
}

HTML:

<html>
  <head>
    <title>Add Entry</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
      <h2>Add Item:</h2>
      Stock ID: <input type ="text" name ="stockId" value="???"> <br> <--how to get it?
      Item Name: <input type ="text" name ="name"> <br>
      Unit Price: <input type ="text" name ="unitPrice"> <br>
      On Stock : <input type ="text" name ="stock"> <br><br>
      <input type ="submit" value ="Add Item">
  </body>
</html>
  • 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-20T08:22:22+00:00Added an answer on May 20, 2026 at 8:22 am

    You’re approaching this the wrong way. HTML belongs in JSP files, not in Servlet classes. Also, EL ${} doesn’t run in plain HTML files at all, but in JSP files only. Rename your .html files to .jsp. This way EL like ${param.id} will then also work, even though you still have a XSS attack hole open.

    See also:

    • Our JSP wiki page
    • Our Servlets wiki page

    (please read them, they contains hello world examples which should turn on some lights in your head)

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

Sidebar

Related Questions

I've been asked (as part of homework) to design a Java program that does
I have developed a java program as a part of my homework and have
as part of a homework assignment for my security class, I'm supposed to add
First off, this is part of an extra credit homework, so please do not
As part of a homework assignment in Lisp, I am to use apply or
As part of a homework assignment I need to concatenate certain values in an
This is part of a homework assignment. I've got several questions asking find the
I am trying to learn TDD and this is part of my homework I
(this is indirectly a part of a much larger homework assignment) I have something
I'm doing a homework in MARS simulator (Assembly) and I'm stuck on one part.

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.