How to check for a session in a jsp page?

When I give for a session check as given in this page in Websphere ,I get a null pointer exception whether I login using a login page or not.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<%
  if(session.getAttribute("name")==null)
	  %>
	  <jsp:forward page="errorPage.jsp"></jsp:forward>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-9" />
<title>Administration Panel</title>

<link href="style.css" rel="stylesheet" type="text/css" ></link>

 <script src="js/jquery-1.js" type="text/javascript"></script>
  	<script type="text/javascript" charset="utf-8">
	//tabbed forms box

		$(function () {
			var tabContainers = $('div#forms > div.innerContent'); // change div#forms to your new div id (example:div#pages) if you want to use tabs on another page or div.
			tabContainers.hide().filter(':first').show();
			
			$('ul.switcherTabs a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('ul.switcherTabs li').removeClass('selected');
				$(this).parent().addClass('selected');
				return false;
			}).filter(':first').click();
		});
	
		$(function () {
			var tabContainers = $('div#menu > div.innerContent'); // change div#forms to your new div id (example:div#pages) if you want to use tabs on another page or div.
			tabContainers.hide().filter(':first').show();
			
			$('ul.switcherTabs a').click(function () {
				tabContainers.hide();
				tabContainers.filter(this.hash).show();
				$('ul.switcherTabs li').removeClass('selected');
				$(this).parent().addClass('selected');
				return false;
			}).filter(':first').click();
		});
		
		</script>
</head>

<body>

<div id="container">
    <div id="header">
      <div id="logo">
        <h1><span><a >Ministry of Law</a></span></h1>
        <p>Courts Administration</p>
      </div>
      <div id="userBox">
        <p><img src="images/icon_user.gif" width="16" height="19" alt=" " /> &nbsp;Hello, <a class="white"><% out.println(session.getAttribute("name")); %></a>. |<a href="../login/logout.jsp">Logout</a></p>
       
      </div><!-- end of #userBox -->
      <div id="menu">
        <ul>
          
          <li class="selected">
          <span class="selected-arrow">&nbsp;</span>
          <a href="dash.jsp">Dashboard</a>
          <ul>
              <li class="selected"><a href="../dash/dash.jsp">Send Mail</a></li>
              <li ><a href="../dash/inbox.jsp">Inbox</a></li>
              <li ><a href="../dash/sentbox.jsp">SentBox</a></li>
              <li><a href="../dash/adminchangepassword.jsp">Change Password</a></li>
            </ul>
          
          </li>
                 
          <li><a href="../dash/admincasedash1.jsp">Cases</a></li>
          <li><a href="../dash/adminuserdash1.jsp">Users</a></li>    
           <li><a href="../dash/adminlawyerdash1.jsp">Lawyers</a>    
                  
          </li>
          <li><a href="../dash/adminjudgedash1.jsp">Judges</a></li>
        </ul>
       
      </div><!-- end of #menu -->
      
  </div><!-- end of  #header -->
      <hr />    
<div id="content">
        <div id="leftBox">
          <div id="pageIntro">
            <h2>Welcome to Indian Courts Admin Panel</h2>
            
          </div>
          <div class="contentBox" id="forms">
            <div class="contentBoxTop">
              <h3>Courts Messaging System</h3>
                <ul class="switcherTabs">
                    <li class="selected"><a href="#box-1">Send Mail</a></li><!-- the link location of this tab refers to the id of the related div -->
                   
                </ul>
            </div>
            <div class="innerContent" id="box-1">
              <form id="form1" name="form1" method="post" action="../dash/messageprocess.jsp">
                From
                <br />
                <label class="smallInput" id="fromadd"><% out.println(session.getAttribute("name")); %></label>
                 
                <p>Recipient<br />
                  <label  class="mediumInput">
                    <input type="text" name="toadd" size="127"/>
                  </label>
                  </p>
                <p>Subject <br />
                  <label  class="largeInput">
                    <input type="text" name="msgsubject" size="127"/>
                  </label>
                  <br />
                  </p>
                <p>Message<br />
                  <label class="textarea">
                    <textarea name="msg" rows="6" cols="80"></textarea>
                  </label>
                  </p>
                <p>
			<input name="" type="image" src="images/bt_submit.gif" />
                  </p>
              </form>
            </div><!--end of #box-1-->
            <div class="innerContent" id="box-2" style="display:none">
            Box-2 content goes here
            </div>
            
          </div>
<hr />
          
          <hr />
          <div class="contentBox">
            <div class="contentBoxTop">
              <h3></h3>
            </div>
            <div class="innerContent">
              
            </div><!--end of #box-3-->
          </div>
<hr />
      </div><!-- end of #leftBox -->
        

        
  </div><!-- end of #content -->
<br class="clearFix" />
</div><!-- end of #container -->
<hr />
<div id="footerWrap">
  <div id="footer">
  
      <div id="footRight">
        <div id="footStats">
        
        </div>
        Copyright 2010 Trojans<br />
          <span class="white">The Trojans</span>
              </div>
  </div>
  <br class="clearFix" />
</div>
</body>
</html>

Open in new window

LVL 1
akashsureshAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sathish David Kumar NArchitectCommented:
your doing correct but your not open { } in the pgm

>>>>>>

<%
  if(session.getAttribute("name")==null)
          %>
0
akashsureshAuthor Commented:
I did not get what you said,sir.What should I do?
0
Sathish David Kumar NArchitectCommented:
what your checking in the line

>>
<%
  if(session.getAttribute("name")==null)
          %>
your using if loop  but ur not open the open baranthesh

like
<%
  if(session.getAttribute("name")==null)  {
          %>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KuppingerCole Reviews AlgoSec in Executive Report

Leading analyst firm, KuppingerCole reviews AlgoSec's Security Policy Management Solution, and the security challenges faced by companies today in their Executive View report.

Sathish David Kumar NArchitectCommented:
like
<%
  if(session.getAttribute("name")==null) {   i added this
          %>
0
akashsureshAuthor Commented:
Ok i tried it,now its working.But why is it not going to error page when it is null
0
Sathish David Kumar NArchitectCommented:
its from ur screen(jsp page)  not in java . here your not handle that  exception  like java throw or throws
so it will show in the browser itself . ...
0
akashsureshAuthor Commented:
Anyway to make it call the error page if session is null?
0
Sathish David Kumar NArchitectCommented:
depend upon ur desgin only it will call. as i mentioned above ur not handle that !! so it wont go..

eg: Now your asking like this only

your creating a class called a . but ur not calling the class .  why a class values is printed ..

I think ur understand what i am saying
0
Sathish David Kumar NArchitectCommented:
why a class values is not printed
0
akashsureshAuthor Commented:
Yes I understand,I need to write a code to handle the error.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.