Problem With Servlet

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • judge82
    New Member
    • Jul 2007
    • 24

    #1

    Problem With Servlet

    I getting error msg that line six is not supported by -source 1.4, try -source 1.5 to enable annotations. I am new to servlet and I need help asap
    thanks in advance
    Code:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    
    @SuppressWarnings("unchecked")
    
    public class ShowItems extends HttpServlet {
      public void doGet(HttpServletRequest request,
                        HttpServletResponse response)
          throws ServletException, IOException {
        HttpSession session = request.getSession();
        ArrayList<String> previousItems =
          (ArrayList<String>)session.getAttribute("previousItems");
        if (previousItems == null) {
          previousItems = new ArrayList<String>();
          session.setAttribute("previousItems", previousItems);
        }
        String newItem = request.getParameter("newItem");
        if ((newItem != null) &&
            (!newItem.trim().equals(""))) {
          previousItems.add(newItem);
        }
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        String title = "Items Purchased";
        String docType =
          "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
          "Transitional//EN\">\n";
        out.println(docType +
                    "<HTML>\n" +
                    "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
                    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
                    "<H1>" + title + "</H1>");
        if (previousItems.size() == 0) {
          out.println("<I>No items</I>");
        } else {
          out.println("<UL>");
          for(String item: previousItems) {
            out.println("  <LI>" + item);
          }
          out.println("</UL>");
        }
        out.println("</BODY></HTML>");
      }
    }
  • judge82
    New Member
    • Jul 2007
    • 24

    #2
    can i get any help here please!

    Comment

    • Laharl
      Recognized Expert Contributor
      • Sep 2007
      • 849

      #3
      I believe that's telling you to use the -source 1.5 tag when compiling via command line. If you're not using a command line compiler, update your IDE...

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by judge82
        I getting error msg that line six is not supported by -source 1.4, try -source 1.5 to enable annotations. I am new to servlet and I need help asap
        thanks in advance
        Code:
        import java.io.*;
        import javax.servlet.*;
        import javax.servlet.http.*;
        import java.util.*;
        
        @SuppressWarnings("unchecked")
        Why did you type in that line anyway if you don't know what it means? It's an
        'annotation' which, in this case is just a compiler directive telling the compiler
        that it shouldn't whine about unchecked, non type safe method invocations.

        Annotations didn't exist in Java 1.4 yet, you need Java 1.5 or later. That's what
        the error diagnostic is trying to tell you.

        kind regards,

        Jos

        Comment

        Working...