| | |
Scramble using JSP
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2008
Posts: 5
Reputation:
Solved Threads: 0
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.
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.
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:-
But you need to check if the contents of the two strings
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.
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)
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)
target = new String("jack"); guessed = target; 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)
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.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
"How to ask questions the smart way ?"
"How to ask questions the smart way ?"
Would you mind to share your solution?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Other Threads in the JSP Forum
- Previous Thread: Jsp tag
- Next Thread: help pls... linking of data to the jsp page in getting the data to the database?
| Thread Tools | Search this Thread |
apache array backbutton combobox comma connection csv database development directorystructure dropdownlist dynamicpagetitles eclipse frames glassfish ie8 imagetodatabse imageupload integer internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 mysql netbeans network parameters passing ping printinserverinsteadofclient read redirect request.getparameter response seperated servlet servletdopost()readxml sessions software sql ssl state_saving_method stocks sun tomcat tutorial update values video web write






