?
Solved

screen resolution on JSP page

Posted on 2005-03-25
7
Medium Priority
?
2,288 Views
Last Modified: 2012-06-22
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
Comment
Question by:ajaydesai9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 21

Accepted Solution

by:
MogalManic earned 500 total points
ID: 13642872
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
 
LVL 19

Assisted Solution

by:Kuldeepchaturvedi
Kuldeepchaturvedi earned 500 total points
ID: 13644434
or use javascript in onload to determine the size of the client and then adjust the page accordingly
0
 
LVL 1

Assisted Solution

by:vijaydogra
vijaydogra earned 500 total points
ID: 13658314
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
 
LVL 3

Assisted Solution

by:arun99907
arun99907 earned 500 total points
ID: 13661642
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
The Summer 2017 Scholarship Winners have been announced!
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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