• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2395
  • Last Modified:

screen resolution on JSP page

I am very new to programming so solution in complete syntax will be great!

I am using top navigation on my web site. This navigation is build inside table. This navigation has tabs. I am including this top navigation on my .JSP pages. I want to do following: When user has 800X600 resolution I want to align my navigation table to left, and when user has 1024X768 resolution I want to align my navigation table to right. I have following script that detects browser resolution. But how can I create jsp variable that I can use in my JSP page to say following: <table If (var for 800X600) align=left else align=right>.

<SCRIPT language="JavaScript">
<!--
if ((screen.width>=1024) && (screen.height>=768))
{
 ????????????
}
else
{
  ??????????
}
//-->
</SCRIPT>

0
ajaydesai9
Asked:
ajaydesai9
4 Solutions
 
MogalManicCommented:
The server has no way of knowing the client screen size unless you tell it.

Do you have a Login page?  If so, then the user posts their username/password, also post the screen height.  Then store the screen height on the session.

Once it is on the session, you can have code like this:

<table align='<%=(Session.getAttribute("clientHeight").intValue()>1024) ? "right" : "left"%>'>
...
</table>
0
 
KuldeepchaturvediCommented:
or use javascript in onload to determine the size of the client and then adjust the page accordingly
0
 
vijaydograCommented:
Hi Ajay

You can have two pages wherein one page you have the navigation table to right aligned and in other to the left.
So depending on the screen width and height you can redirect to that page.

Or you can use document.write in the javascript as follows:
<SCRIPT language="JavaScript">
<!--
if ((screen.width>=1024) && (screen.height>=768))
{
 document.write("<table align='right'>The whole navigation table</table>");
}
else
{
 document.write("<table align='left'>The whole navigation table</table>");
}
//-->
</SCRIPT>

0
 
arun99907Commented:
You need not have a separate Login.jsp page for submitting it as a variable.

People normally dont prefer to load session with variables. But in your case we have to use two session variables.

1. screenHeight
2. screenWidth

say u are in firstPage.jsp
<%
String screenHeight = "";
String screenHeight = "";
 
  if(request.getParameter("screenHeight")!=null)
        screenHeight = (String)request.getParameter("screenHeight");
  if(request.getParameter("screenWidth")!=null)
        screenWidth = (String)request.getParameter("screenWidth");

   if(session.getAttribute("screenHeight")!=null)
              screenHeight = (String)session.getAttribute("screenHeight");
     
    if(session.getAttribute("screenWidth")!=null)
             screenWidth = (String)session.getAttribute("screenWidth");          

   if(screenHeight.length()>0 && screenWidth.length()>0)
     {
         // set these values in session so that it need not be calculated next time.
         if(session.getAttribute("screenHeight")!=null)
           session.setAttribute("screenHeight",screenHeight);
       
        if(session.getAttribute("screenWidth")!=null)
           session.setAttribute("screenWidth",screenWidth);
      }
%>

<html>
<head>
  <script language='JavaScript'>
      function loadScreenVariables()
       {
            var screenHeight = '<%=screenHeight%>';
            var screenWidth = '<%=screenHeight%>';
           
           if(!(screenHeight.length() > 0 && screenHeight.length() > 0)) // not sure abt syntax of finding the variable string length. - Incase both these values are empty variables as it will happen for the first time.
         {
              // load variables.
              document.firstPageForm.screenHeight.value = screen.Height;
              document.firstPageForm.screenWidth.value = screen.Width;

              document.firstPageForm.action = "firstPage.jsp";
              document.firstPageForm.submit();
          }
       }
 </script>
</head>

<form name=firstPageForm onLoad="javaScript:loadScreenVariables()">
 <input type=hidden name=screenHeight>
 <input type=hidden name=screenWidth>

// rest of the logic.

// down in the logic you can use the server side variable, screenHeight and screenWidth to find out where to keep your navigation bars.

<form>
</html>



Logic: I hope u undrestood the logic here.

Load the same file once to retrieve the screen dimensions on server side.

You can in no other way get Client side variable values into a server side variables.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now