Results 1 to 3 of 3
  1. #1
    midpitts is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default assigned value never used error

    I am trying to learn NetBeans and have typed the code from the book "murach's Java Servlets and JSP Second Edition", pg 219. I am getting an error about the assigned value for message and url never being used. I don't see the problem in the code. I even found the code online and copy/pasted it, but it has the same problem. Any suggestions on what I need to do?

    Java Code:
    package email;
    
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    import business.User;
    import data.UserIO;
    
    public class AddToEmailListServlet extends HttpServlet
    {    
        protected void doPost(HttpServletRequest request, 
                              HttpServletResponse response) 
                              throws ServletException, IOException
        {
            // get parameters from the request
            String firstName = request.getParameter("firstName");
            String lastName = request.getParameter("lastName");
            String emailAddress = request.getParameter("emailAddress");
    
            // get a relative file name
            
            // use regular Java classes
            User user = new User(firstName, lastName, emailAddress);
          //--------------------------------------------------
            // validate the parameters
    String message = "";
    String url = "";
    if (firstName.length() == 0 ||
    lastName.length() == 0 ||
    emailAddress.length() == 0)
    
    {
    message =
    "Please fill out all three text boxes.";
    url = "/join_email_list.jsp";
    }
    else
    {
    message = "";
    
    ServletContext context = getServletContext();
    String path = context.getRealPath(
    "/WEB-INF/EmailList.txt");
    UserIO.addRecord(user, path);
    url = "/display_email_entry.jsp";
    }
    request.setAttribute("user", user);
    request.setAttribute("message", message);
    // forward request and response to the view
    RequestDispatcher dispatcher =
    getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: assigned value never used error

    That's not an error, it's a warning, because you assign "" to both, but then you change the value before it ever gets used.
    Don't bother assigning anything to either at the declaration.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    midpitts is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Re: assigned value never used error

    Thanks for solving this for me. I am going to try to find a way to worn others using this book to not put in the "" assignments.

Similar Threads

  1. Replies: 3
    Last Post: 05-08-2012, 06:26 PM
  2. Variable not being assigned?
    By Evan.C in forum New To Java
    Replies: 4
    Last Post: 03-23-2012, 06:11 PM
  3. thread ref assigned to null
    By rajinder5 in forum Threads and Synchronization
    Replies: 2
    Last Post: 12-22-2010, 08:47 PM
  4. Replies: 1
    Last Post: 12-05-2009, 08:28 AM
  5. FInal field cannot be assigned
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-13-2007, 03:26 PM

Posting Permissions

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