I am using form based, declarative security approach. And, when some user, on login form enters user credentials (username and password), he is being redirected to certain/secured jsp page.
Part of that page content is:Hello <%=request.getUserPrincipal().getName().toString()%> You are able to view this page because you are authorized user.You can see that this is implemented using JSP scriptlet. And this works. I would like to use JSTL instead of scriptlet.
So, instead of scriptlet, I put this JSTL code: <c:out value="${requestScope.userPrincipal.name}"/>, but not getting user's username with it. Basically, I don't clearly understand where and how are these objects/user credentials being stored with Form based JAAS.
I would like on JSP page to check if some user is already logged in. So, if there is logged user to display user's name (also with JSTL).Something like this:
<c:if test="${not empty sessionScope.userPrincipal}">
User <c:out value="${sessionScope.userPrincipal.name}" />
</c:if>
Here I tried with sessionScope but still not getting anything.
The information is getting stored in the session and i am able to retrieve the same for single user. The trouble starts when 2 user logged in from different browser (for example chrome, IE) from the same machine. The 2nd logged in user, overwrite the session information of first user.
How to prevent this.
My environment: Windows 7 64 bit, IBM websphere server, Oracle 11g, JSP, Sevrlet.
System.out.print("To begin, please enter 1 to choose stand tickets or 2 to choose terrace tickets for your party. "); int standOrTerraceTickets = aScanner.nextInt(); while (standOrTerraceTickets != 1 && standOrTerraceTickets != 2) { System.out.print("Invalid input. Please enter 1 for stand tickets or 2 for terrace tickets. "); standOrTerraceTickets = aScanner.nextInt(); }
Okay I thought I had this working properly so that when the user entered anything other than 1 or 2 they would keep getting an error invalid input, however, that only works when the user enters an integer. If the user enters anything other than a number, the program crashes. How does one prevent this from happening?
I have a question about how to check for a session as the user goes through different pages. I am using Java beans and EL to pass data from page to page but I cannot figure out how to check for a session on the pages without the use of a scriptlet with an if else statement in it.
I do not want the user to be able to access any pages unless they are logged in. With a scriptlet, I can create a statement that says if session exists show name else redirect to login page.
From what I have read and what some of the wonderful members here have told me, scriptlets are a big no no these days. So, how do I do these without the use of a scriptlet?
I am trying to write a simple program that checks if a user's input has a specific letter using the ".contains" method but its not doing what i wanted to do. here is my code below.
import java.util.Scanner; public class secret { public static void main(String args[]) { Scanner sc; char hidden='a'; String guess;
The code for my button is below - I know it is wrong and that I need to change line 8 at least,so I am technically asking the property object if there is a key_name there but I dont quite get how to do that
//code for button
JButton btnSearch = new JButton("Search"); btnSearch.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //find selected command String key_name = textFieldSearch.getText();
[Code] ....
I basically just want the user typed in word to be checked against a keyword in a proeprties file and if it exists, pull the key and the value back into a panel ....
/** * Auto Generated Java Class. */ import java.util.*; public class Hangman { public static void main(String[] args) { Scanner input = new Scanner (System.in); int guess; boolean revealed[] = {false, false, false, false, false}; String word [] = {"c", "a", "n", "a", "d", "a"};
[Code] ....
I am not sure how to make the program check if the letter entered by the user matches the one in the array. also i am not sure how to make the program run again with a new word.
Write a program that prompts the user for an input number and checks to see if that input number is greater than zero. If the input number is greater than 0, the program does a multiplication of all the numbers up to the input number starting with the input number. For example if the user inputs the number 9, then the program displays the following sum:
9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1 = 362880
That's the question I'm getting and so far all I've got is
import java.util.Scanner; public class Lab4Q3 { public static void main (String[] args) { int keyboard;
I decided to code this quiz I took in class about asking the user to input a string and the code is suppose to check for upper case letters. If a upper case letter is found, it should increase a count by one. Once the check is done, it should display the number of uppercase letters. For some reason I am getting this weird compile error stating that symbols can't be found...
Java Code:
import java.util.*; import java.lang.*; public class StringCheck{ public static void main(String[] args){ Scanner input = new Scanner(System.in); System.out.println("please enter a string: " ); String s = input.nextLine();
I am having trouble figuring out how to check for win in tic tac toe, the way my teacher wants it is with various if statements but im not sure what to put in the parentheses. I think it would be something like
This SHOULD be a simple program, the gist of it is Given an element E and the array A that represents a set X (user input), write a program that determines whetherE is an element of X.I have the array list all set up to take the user input and make zero the last element of the array. I want user to input numbers into array, then have fixed numbers for E and check to see if E is in the Array. I guess I'm not sure how to check the array and see if E is in the array? Here is what I have so far...
import java.util.ArrayList; import java.util.Scanner; import java.util.List; import java.util.InputMismatchException; public class Set { public static void main(String[] args) { List<Integer> userInputArray = new ArrayList<Integer>();
I am having an issue with my swing gui. I dynamically create tabs with information (textfields, checkboxes, combo boxes) and when I select the checkbox it disables or enables a textfield. Now when I select the checkbox it seems to resize everything, specifically my textfields from say 9 columns to probably one. I"m a little unsure why it is doing this but I have a feeling it may be an inheritence issue.
My code is below for my generation of the tabs and of the rest of the information on the gui. The gui is an inner rid layout with a top and bottom pane that are both gridbaglayouts and an outter pane as well. I am thinking I am missing something in the grid layout setup that is causing this.
1. In jsp 1 , i have 3 checkboxes(chkbox1,chkbox2,chkbox3) , if i select check boxes (chkbox1, chkbox2), and click on submit, corresponding two text fields (chkbox1,chkbox2) will have to appear in the next jsp i.e., jsp 2.
2. In jsp 1 , i have 3 checkboxes(chkbox1,chkbox2,chkbox3) , if i select check boxes (chkbox2, chkbox3), and click on submit, corresponding two text fields(chkbox2,chkbox3) will have to appear in the next jsp i.e., jsp 2.
Like this, which ever checkbox i select, corresponding text fields should appear in the subsequent jsp.
import java.util.Scanner; public class Project_5 { public static void main (String[] args) { Scanner input= new Scanner (System.in);
[code]....
So I'm attempting to have this program take the users input of integers, pressing enter in between each one. If they enter a negative number it lets them know that its invalid. At the end of the program it takes all of the valid integers entered and must add them and average them. I've put the final println in there as a placeholder. If the user types in "6" then presses enter and types in "3" , the output is:
There were 3 valid numbers entered. The sum of the valid numbers was --- and the average was ---. There were 0 invalid numbers entered.
It then continues on allowing the user to enter more values. Here is the example output for correct code"
Enter a positive value (EOF to quit): 4 Enter a positive value (EOF to quit): 7 Enter a positive value (EOF to quit): 8 Enter a positive value (EOF to quit): 2 Enter a positive value (EOF to quit): -1 The number "-1" is invalid.
Enter a positive value (EOF to quit): 8 Enter a positive value (EOF to quit): 0 Enter a positive value (EOF to quit): -4 The number "-4" is invalid.
Enter a positive value (EOF to quit): CTRL-D
There were 6 valid numbers entered. The sum of the valid numbers was 29 and the average was 4.83. There were 2 invalid numbers.
Write a java program that will ask a user to input grades until the user inputs the sentinel value -1. The program should test each input to determine whether 0<=grade<=100. If the grade entered is within this range, the program should print "Grade accepted;" if not, the program should print "Invalid input".
Basically I need to make a program prompts the user for an integer, check to make sure the length entered by the user is a power of 2 and at least 2. Then I need to convert from base e to base 2 then I need to print the tick marks of a ruler based of the value of the length.
I got the whole converting thing working and the check for a power of 2, that wasn't an issue because it didn't require any recursion. I just don't know how to print out the proper tick mark values.
The way it is supposed to work is that it needs to look like this. Say the user enters 8;
012131210 012345678
Or if the user enters 16;
01213121412131210 01234567890123456
The bottom row is pretty much just the index value, that I print fine.
The top row though is supposed to be the length of the ticks on a ruler, with the middle most value being the value of the conversion from base e to base 2 from above. I can get that printed and what I get just looks like this.
For 8;
000030000 012345678
For 16;
00000000400000000 01234567890123456
As you can see I can get the middle value and the index values below but I don't know how to use recursion to get the right numbers.
Here's my current code.
import java.util.*; public class TickMarks { public static void main (String args[]){ Scanner input = new Scanner(System.in); boolean looping = true; while(looping == true){ System.out.print("Please enter a length: ");
[Code]...
Now the methods isPowerOfTwo() and printLength() both work fine. However, I'm not sure how to get the left and right side working.
My thoughts were to split the length in half and get a left and right side. I gave both of them arrays so I can keep track of the values. Now as you've seen above I get all zeros and I know it's because that's the default value in an array, I just don't know how to get the proper values.
I have been struggling with this program for weeks. This program is supposed to take a user's inputted odd number and then print out all prime numbers lower than that number.
public class PrimeNumber { Scanner scan = new Scanner(System.in); int userNum; String neg;
I'm trying to come up with a method that would validate each turn a player makes. For a turn to be valid, it has to only contain numbers from 0 to 3(inclusive) and at least one digit must not be 0. Here is what I`ve come up with so far. For example, with "303" as the number and "101" as the turn, the turn would be valid and my method should return true, but it does not.
public static boolean turnIsValid (String number, String turn ){ boolean rep=false; int pos1=0; char min='0'; char max='3'; while(number.length()==turn.length()&&pos1<turn.length()){