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, 05:54 PM
Member
 
Join Date: Dec 2007
Posts: 7
jellyfish888 is on a distinguished road
I need help with my java servlet homework(average)
My teacher asked me to do a java servlet code that will get the average of x numbers...I am planning to make a code that will put a dilimeter(such as comma or space) to ask the user to input their x numbers...unfortunately I don't know how to make this and how I am going to compute for the average...please help me...for now I only manage to make the very basic of the script...please help me...

My HTML code:
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>Average</p> <form action="AverageNumber" method=get> <p><input type=text name=number></p> <input type=submit name=submit value=Submit> </form> </body> </html>
This is my servlet which I don't know how to continue:
Code:
import java.io.*; import java.util.Arrays; import javax.servlet.*; import javax.servlet.http.*; public class AverageNumber extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { int number = Integer.parseInt(request.getParameter("number")); 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(answer); out.println("</body>"); out.println("</html>"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-22-2007, 06:24 AM
Member
 
Join Date: Dec 2007
Posts: 7
jellyfish888 is on a distinguished road
edited java servlet
I've done some changes in my code...This time I was able to somehow organize my thought to compute for average...I used stringtokenizer to split the numbers...unfortunately I am experiencing some errors...please help me...please check my code...

Code:
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class AverageNumber extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { int number = Integer.parseInt(request.getParameter("number")); 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(answer); out.println("</body>"); out.println("</html>"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doGet(request, response); } public int process(Integer number){ int count=0; int sum=0; StringTokenizer st=new StringTokenizer(number); while (st.hasMoreTokens()){ System.out.println(st.nextToken()); } for (int=0; i<number.length; i++){ count=count+1; sum=average+number; } int average=sum/count; System.out.println("Result: "+average); } } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-23-2007, 10:57 PM
Member
 
Join Date: Dec 2007
Posts: 1
james_kabi is on a distinguished road
I hope this could be helpful
Hey buddy,

I attached two zip files, one of them in AverageNumber.zip which is a web application (source included) in order to deploy it, first extract it and then copy the extracted folder to webapps directory of your tomcat,

the second one is a netbeans project (AverageNumber_nbproject.zip), if you download the netbeans 6.0 IDE. you can extract the zip file and open it with netbeans.

download the NetBeans 6.0 IDE from : Welcome to NetBeans
it'll be solve most of your programming problems.

I hope it would be helpful

Regards,

james
Attached Files
File Type: zip AverageNumber.zip (4.6 KB, 6 views)
File Type: zip AverageNumber_nbproject.zip (19.0 KB, 0 views)
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
Calculate Average sthack99 New To Java 4 06-13-2008 12:09 PM
I need help with my java servlet homework(add,edit and delete) jellyfish888 Java Servlet 3 12-26-2007 07:42 AM
Help with my java servlet homework jellyfish888 Java Servlet 2 12-21-2007 06:41 PM
working out wrong average gemtez New To Java 4 12-12-2007 09:35 AM
get the average and maximum score Eric Advanced Java 2 07-01-2007 05:15 AM


All times are GMT +3. The time now is 06:15 AM.


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