Results 1 to 3 of 3
  1. #1
    jellyfish888 is offline Member
    Join Date
    Dec 2007
    Posts
    7
    Rep Power
    0

    Default Help with my java servlet homework

    I am getting error saying:
    root cause

    java.lang.Error: Unresolved compilation problem:
    Arrays cannot be resolved

    Sorting.process(Sorting.java:38)
    Sorting.doGet(Sorting.java:14)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:690)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:803)

    My code:
    This is my HTML script
    Java Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <p>Sorting arrays</p>
    <form action="Sorting" method=get>
    <p>1 <input type=text name=word></p>
    <input type=submit name=sort value=Submit>
    </form>
    </body>
    </html>
    This is my servlet:
    Java Code:
    
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    
    public class Sorting extends HttpServlet
    {
        public void doGet(HttpServletRequest request,
             HttpServletResponse response)
                throws IOException, ServletException
        {
          String word = request.getParameter("word");
          word = process(word);
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();
          out.println("<html>");
          out.println("<head>");
          out.println("<title>Sorting Servlet</title>");
          out.println("</head>");
          out.println("<body>");
          out.println(word);
          out.println("</body>");
          out.println("</html>");
          }
    
          public void doPost(HttpServletRequest request,
          HttpServletResponse response)
          throws IOException, ServletException
          {
          doGet(request, response);
          }
    
          public String process(String word) {
          StringBuilder buf = new StringBuilder(512);
          if(word != null && word.trim().length() != 0) {
          String arr[] = word.replaceAll("\\s+", "").split(",");
          Arrays.sort(arr);
          for(String str : arr) {
    
          buf.append(str).append("<br>");
          }
    
          }
    
          else {
          buf.append("<br>").append("No input supplied").append("<br>");
          }
          return(buf.toString());
          }
          }

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default

    You've missed an import in your class. The Arrays class is in the java.util package.

    Java Code:
    import java.util.Arrays;

  3. #3
    jellyfish888 is offline Member
    Join Date
    Dec 2007
    Posts
    7
    Rep Power
    0

    Default

    Thank you...It is the problem...thank you for the answer...

Similar Threads

  1. Removal of Homework Requests
    By CaptainMorgan in forum Suggestions & Feedback
    Replies: 14
    Last Post: 08-03-2008, 09:21 PM
  2. Tough Homework Questions, PLEASE HELP!
    By passage in forum New To Java
    Replies: 21
    Last Post: 01-16-2008, 11:04 PM
  3. Replies: 3
    Last Post: 12-26-2007, 06:42 AM
  4. I need help with my java servlet homework(average)
    By jellyfish888 in forum Java Servlet
    Replies: 2
    Last Post: 12-23-2007, 09:57 PM
  5. Homework PREREQUISITE Problem
    By ChrisC in forum New To Java
    Replies: 7
    Last Post: 11-27-2007, 05:36 AM

Posting Permissions

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