469,578 Members | 1,322 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

how to pass parameters to jsp

hi to all,


in my jsp page hyper links are there starting from "A" to "Z". when ever i click on any one of those links it should call itself and pass a parameter of its value. for example if i click on "A" same page should display once again with a parameter "A". how to do it. i am also sending some code also

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page import="java.sql.*;"%>
  3. <%@ page session="true"%>
  4. <%!String un,per=null;%>
  5. <%
  6.         per=(String)session.getValue("per");
  7.         if(per==null)
  8.         {
  9.         }
  10.         else
  11.         {
  12.             out.println(per);
  13.         }
  14.         un=(String)session.getValue("un");
  15.         Connection con;
  16.         Statement st;
  17.         ResultSet rs;
  18.     try{
  19.         Class.forName("com.mysql.jdbc.Driver").newInstance();
  20.  
  21.         con=DriverManager.getConnection("jdbc:mysql://localhost/experience","root","");
  22.         st=con.createStatement();
  23.         /*if(!isNull(per))
  24.         {
  25.             rs=st.executeQuery("Select EmpName from empdata");
  26.         }*/
  27.         }
  28.         catch(Exception e)
  29.         {
  30.             out.println(e);
  31.         }
  32. %>
  33. <html>
  34.     <head>
  35.         <link rel="stylesheet" href="./css/Form.css">
  36.         <script language="javascript">
  37.         function per(String val)
  38.         {
  39.             document.f1.per.value=val;
  40.         }
  41.     </script>
  42.     </head>
  43.     <body id="body">
  44.     <%out.println("User is <b>"+un+"</b><a href='./LoginForm.html' target='body'><font size=1>(LOGOUT)</font></a>");
  45.     %>
  46.     <h1><center>Welcome To Admin Page</center></h1>
  47.     <h3>Click here to display all the employees</h3>
  48.     <form name="f1">
  49.         <input type="hidden" name="per">
  50.         <center>
  51.             <table>
  52.                 <tr>
  53.                     <td><a href="./Admin.jsp" onclick=per("A")>A</a>|</td>
  54.                     <td><a href="./Admin.jsp" onclick=per("B")>B</a>|</td>
  55.                     <td><a href="./Admin.jsp" onclick=per("C")>C</a>|</td>
  56.                     <td><a href="">D</a>|</td>
  57.                     <td><a href="">E</a>|</td>
  58.                     <td><a href="">F</a>|</td>
  59.                     <td><a href="">G</a>|</td>
  60.                     <td><a href="">H</a>|</td>
  61.                     <td><a href="">I</a>|</td>
  62.                     <td><a href="">J</a>|</td>
  63.                     <td><a href="">K</a>|</td>
  64.                     <td><a href="">L</a>|</td>
  65.                     <td><a href="">M</a>|</td>
  66.                     <td><a href="">N</a>|</td>
  67.                     <td><a href="">O</a>|</td>
  68.                     <td><a href="">P</a>|</td>
  69.                     <td><a href="">Q</a>|</td>
  70.                     <td><a href="">R</a>|</td>
  71.                     <td><a href="">S</a>|</td>
  72.                     <td><a href="">T</a>|</td>
  73.                     <td><a href="">U</a>|</td>
  74.                     <td><a href="">V</a>|</td>
  75.                     <td><a href="">W</a>|</td>
  76.                     <td><a href="">X</a>|</td>
  77.                     <td><a href="">Y</a>|</td>
  78.                     <td><a href="">Z</a>|</td>
  79.                 </tr>
  80.             </table>
  81.         </center>
  82.     </form>
  83.     </body>
  84. <html>
  85.  
  86.  
if i tried like this i am not getting the correct. can any one tell where i am doing mistake

regards



regards
Apr 16 '07 #1
1 2617
r035198x
13,262 8TB
hi to all,


in my jsp page hyper links are there starting from "A" to "Z". when ever i click on any one of those links it should call itself and pass a parameter of its value. for example if i click on "A" same page should display once again with a parameter "A". how to do it. i am also sending some code also

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%@ page import="java.sql.*;"%>
  3. <%@ page session="true"%>
  4. <%!String un,per=null;%>
  5. <%
  6.         per=(String)session.getValue("per");
  7.         if(per==null)
  8.         {
  9.         }
  10.         else
  11.         {
  12.             out.println(per);
  13.         }
  14.         un=(String)session.getValue("un");
  15.         Connection con;
  16.         Statement st;
  17.         ResultSet rs;
  18.     try{
  19.         Class.forName("com.mysql.jdbc.Driver").newInstance();
  20.  
  21.         con=DriverManager.getConnection("jdbc:mysql://localhost/experience","root","");
  22.         st=con.createStatement();
  23.         /*if(!isNull(per))
  24.         {
  25.             rs=st.executeQuery("Select EmpName from empdata");
  26.         }*/
  27.         }
  28.         catch(Exception e)
  29.         {
  30.             out.println(e);
  31.         }
  32. %>
  33. <html>
  34.     <head>
  35.         <link rel="stylesheet" href="./css/Form.css">
  36.         <script language="javascript">
  37.         function per(String val)
  38.         {
  39.             document.f1.per.value=val;
  40.         }
  41.     </script>
  42.     </head>
  43.     <body id="body">
  44.     <%out.println("User is <b>"+un+"</b><a href='./LoginForm.html' target='body'><font size=1>(LOGOUT)</font></a>");
  45.     %>
  46.     <h1><center>Welcome To Admin Page</center></h1>
  47.     <h3>Click here to display all the employees</h3>
  48.     <form name="f1">
  49.         <input type="hidden" name="per">
  50.         <center>
  51.             <table>
  52.                 <tr>
  53.                     <td><a href="./Admin.jsp" onclick=per("A")>A</a>|</td>
  54.                     <td><a href="./Admin.jsp" onclick=per("B")>B</a>|</td>
  55.                     <td><a href="./Admin.jsp" onclick=per("C")>C</a>|</td>
  56.                     <td><a href="">D</a>|</td>
  57.                     <td><a href="">E</a>|</td>
  58.                     <td><a href="">F</a>|</td>
  59.                     <td><a href="">G</a>|</td>
  60.                     <td><a href="">H</a>|</td>
  61.                     <td><a href="">I</a>|</td>
  62.                     <td><a href="">J</a>|</td>
  63.                     <td><a href="">K</a>|</td>
  64.                     <td><a href="">L</a>|</td>
  65.                     <td><a href="">M</a>|</td>
  66.                     <td><a href="">N</a>|</td>
  67.                     <td><a href="">O</a>|</td>
  68.                     <td><a href="">P</a>|</td>
  69.                     <td><a href="">Q</a>|</td>
  70.                     <td><a href="">R</a>|</td>
  71.                     <td><a href="">S</a>|</td>
  72.                     <td><a href="">T</a>|</td>
  73.                     <td><a href="">U</a>|</td>
  74.                     <td><a href="">V</a>|</td>
  75.                     <td><a href="">W</a>|</td>
  76.                     <td><a href="">X</a>|</td>
  77.                     <td><a href="">Y</a>|</td>
  78.                     <td><a href="">Z</a>|</td>
  79.                 </tr>
  80.             </table>
  81.         </center>
  82.     </form>
  83.     </body>
  84. <html>
  85.  
  86.  
if i tried like this i am not getting the correct. can any one tell where i am doing mistake

regards



regards
You can put the value in a hidden input and retrieve using request.getParameter
Apr 16 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Zlatko Matić | last post: by
3 posts views Thread by Zlatko Matić | last post: by
2 posts views Thread by Alex Nitulescu | last post: by
5 posts views Thread by cpnet | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.