Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-21-2007, 07:02 AM
Member
 
Join Date: Dec 2007
Posts: 7
jellyfish888 is on a distinguished road
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
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:
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()); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-21-2007, 10:12 AM
Member
 
Join Date: Jun 2007
Location: Bali, ID
Posts: 98
wsaryada is on a distinguished road
You've missed an import in your class. The Arrays class is in the java.util package.

Code:
import java.util.Arrays;
__________________
Website:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
- Blog:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-21-2007, 06:41 PM
Member
 
Join Date: Dec 2007
Posts: 7
jellyfish888 is on a distinguished road
Thank you...It is the problem...thank you for the answer...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removal of Homework Requests CaptainMorgan Suggestions & Feedback 14 08-03-2008 10:21 PM
Tough Homework Questions, PLEASE HELP! passage New To Java 21 01-17-2008 12:04 AM
I need help with my java servlet homework(add,edit and delete) jellyfish888 Java Servlet 3 12-26-2007 07:42 AM
I need help with my java servlet homework(average) jellyfish888 Java Servlet 2 12-23-2007 10:57 PM
Homework PREREQUISITE Problem ChrisC New To Java 7 11-27-2007 06:36 AM


All times are GMT +3. The time now is 09:27 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org