Connecting Tech Pros Worldwide Forums | Help | Site Map

Problem With Servlet

Newbie
 
Join Date: Jul 2007
Posts: 24
#1: Oct 12 '07
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
Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4. import java.util.*;
  5.  
  6. @SuppressWarnings("unchecked")
  7.  
  8. public class ShowItems extends HttpServlet {
  9.   public void doGet(HttpServletRequest request,
  10.                     HttpServletResponse response)
  11.       throws ServletException, IOException {
  12.     HttpSession session = request.getSession();
  13.     ArrayList<String> previousItems =
  14.       (ArrayList<String>)session.getAttribute("previousItems");
  15.     if (previousItems == null) {
  16.       previousItems = new ArrayList<String>();
  17.       session.setAttribute("previousItems", previousItems);
  18.     }
  19.     String newItem = request.getParameter("newItem");
  20.     if ((newItem != null) &&
  21.         (!newItem.trim().equals(""))) {
  22.       previousItems.add(newItem);
  23.     }
  24.     response.setContentType("text/html");
  25.     PrintWriter out = response.getWriter();
  26.     String title = "Items Purchased";
  27.     String docType =
  28.       "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
  29.       "Transitional//EN\">\n";
  30.     out.println(docType +
  31.                 "<HTML>\n" +
  32.                 "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
  33.                 "<BODY BGCOLOR=\"#FDF5E6\">\n" +
  34.                 "<H1>" + title + "</H1>");
  35.     if (previousItems.size() == 0) {
  36.       out.println("<I>No items</I>");
  37.     } else {
  38.       out.println("<UL>");
  39.       for(String item: previousItems) {
  40.         out.println("  <LI>" + item);
  41.       }
  42.       out.println("</UL>");
  43.     }
  44.     out.println("</BODY></HTML>");
  45.   }
  46. }

Newbie
 
Join Date: Jul 2007
Posts: 24
#2: Oct 12 '07

re: Problem With Servlet


can i get any help here please!
Expert
 
Join Date: Sep 2007
Posts: 856
#3: Oct 13 '07

re: Problem With Servlet


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...
JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#4: Oct 13 '07

re: Problem With Servlet


Quote:

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

Expand|Select|Wrap|Line Numbers
  1. import java.io.*;
  2. import javax.servlet.*;
  3. import javax.servlet.http.*;
  4. import java.util.*;
  5.  
  6. @SuppressWarnings("unchecked")
  7.  

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
Reply