943,651 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 925
  • JSP RSS
Nov 29th, 2008
0

Scramble using JSP

Expand Post »
Hi. I need to do a scramble game.
Simply I need to randomly select a word from my set of strings and print out in shuffled string. Such as if the word is "banana" it should print out something like "anaban" and there should be text field for user to enter and guess the correct word. I also need to keep record correct and wrong number of guesses.
I am quite new to the jsp and couldnt go much further. Please help =(

I have included my jsp file in zip.
Attached Files
File Type: zip scramble.zip (1.5 KB, 11 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zoroman is offline Offline
5 posts
since Nov 2008
Nov 30th, 2008
0

Re: Scramble using JSP

JSPs should only be used for display purposes in Web Applications, kind off like swing and AWT are used for the User Interface. Your actual programming logic should be written in normal Java class, to the methods of which you will pass your parameters (in this case the word to be scrambled) and they will return back the result. So never put your programing logic inside a JSP.
For this small assignment of your you may think the above advice is an overkill but its always better to start using the right approach as early as possible.
By checking out your code I suggest you use consistent indentation. There are some places where you have indented correctly whereas at other places you have just conveniently just forgotten about it. You can read here about the code conventions recommended by Sun while programming in Java.

Also look at the following piece of code:-
java Syntax (Toggle Plain Text)
  1. if (guessed == target){

target and guessed are both String objects. The == operator for in case references to objects checks if target and guessed both point to the same String object. So guessed == target would evaluate to true only in the following case : -
java Syntax (Toggle Plain Text)
  1. target = new String("jack");
  2. guessed = target;
  3. if (guessed == target){

But you need to check if the contents of the two strings target and guessed are the same. So for that you need to use the equals() method of the String class (or equalsIgnoreCase() if you do not wish to consider the case), So the above statement should then be :-

java Syntax (Toggle Plain Text)
  1. if (guessed.equalsIgnoreCase(target)){

There might be a few more problems in your JSP but I suggest you at least implement what has been mentioned here for a start.
Featured Poster
Reputation Points: 653
Solved Threads: 151
Nearly a Posting Virtuoso
stephen84s is offline Offline
1,316 posts
since Jul 2007
Dec 5th, 2008
0

Re: Scramble using JSP

Thank you, I have sorted out
Reputation Points: 10
Solved Threads: 0
Newbie Poster
zoroman is offline Offline
5 posts
since Nov 2008
Dec 6th, 2008
0

Re: Scramble using JSP

Would you mind to share your solution?
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 871
Code tags enforcer
peter_budo is offline Offline
6,654 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Jsp tag
Next Thread in JSP Forum Timeline: help pls... linking of data to the jsp page in getting the data to the database?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC