Solved

Check for a variable if it's available on the server

Posted on 2004-08-14
4
202 Views
Last Modified: 2012-05-05
I want the statement that check if a specific variable is available on the server variables or not.

I need that in order to check for the availability of a specific variable. So that if the any one reached the page directly i can display my own message instead of null pointer exception raised by the compiler
0
Comment
Question by:The_Gutsy
4 Comments
 
LVL 3

Accepted Solution

by:
sbockelman earned 125 total points
ID: 11801237
String sExpectedVariableValue = request.getParameter( "theExpectedVariables" );
if( null == sExpectedVariableValue ) {
    // kick them out!
}

0
 
LVL 3

Assisted Solution

by:pat5star
pat5star earned 125 total points
ID: 11818378
You should store a specific word in the users session from your main entry page, like a login page.

HttpSession session = request.getSession();
session.setAttribute("secretWord", "secret");

Then on every page that you only want 'logged in' users you check for the secretWord like this:

if (null != session.getAttribute("secretWord") && "secret".equals((String)session.getAttribute("secretWord"))) {
  // They are logged in
} else {
  // They are not logged in, send error message...
}

What this does is check that the session attribute "secretWord" is not null and that it does equal the value "secret". If not, you know they came to the page directly and can then handle it whatever way you want.

Hope that helps,

-Pat
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Apache server configuration 7 87
hashcode is calculated on the basis of value object 2 118
constructor overloading 2 86
main method of string class 3 117
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
The business world is becoming increasingly integrated with tech. It’s not just for a select few anymore — but what about if you have a small business? It may be easier than you think to integrate technology into your small business, and it’s likely…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question