Solved

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

Posted on 2004-08-14
4
200 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
Comment Utility
String sExpectedVariableValue = request.getParameter( "theExpectedVariables" );
if( null == sExpectedVariableValue ) {
    // kick them out!
}

0
 
LVL 3

Assisted Solution

by:pat5star
pat5star earned 125 total points
Comment Utility
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now