Solved

jstl getting parameters

Posted on 2013-01-31
3
437 Views
Last Modified: 2013-02-20
I was reading about getting url parameters using jstl.

I wrote followin code


Process.jsp code


<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>My JSP 'Process.jsp' starting page</title>
   
      <meta http-equiv="pragma" content="no-cache">
      <meta http-equiv="cache-control" content="no-cache">
      <meta http-equiv="expires" content="0">    
      <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
      <meta http-equiv="description" content="This is my page">
      <!--
      <link rel="stylesheet" type="text/css" href="styles.css">
      -->

  </head>
 
  <body>
    This is my JSP page. <br>
    <jsp:useBean id="user" class="org.gp.gpr.dto.User" scope="request">
    <jsp:setProperty property="userName" name="user" param="userName"/>
   
    </jsp:useBean>
   
   
 helloo<jsp:getProperty property="userName" name="user"/>
  </body>
</html>


Login.jsp code


<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   
    <title>Login page</title>
   
      <meta http-equiv="pragma" content="no-cache">
      <meta http-equiv="cache-control" content="no-cache">
      <meta http-equiv="expires" content="0">    
      <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
      <meta http-equiv="description" content="This is my page">
      <!--
      <link rel="stylesheet" type="text/css" href="styles.css">
      -->

  </head>
 
  <body>

 <form method="post" action="Process.jsp">
 <br>User Id:<input type="text" name="userId">
 <br>User Name:<input type="text" name="userName">
 <br>User Addr1:<input type="text" name="userAddr1">
 <br>UserAddr2:<input type="text" name="userAddr2">
 <br>City:<input type="text" name="city">
 <br>State:<input type="text" name="state">
 <br>Pincode:<input type="text" name="pin">
<br> <input type="submit">
 </form>
  </body>
</html>







I read

writing below

 <jsp:useBean id="user" class="org.gp.gpr.dto.User" scope="request">
    <jsp:setProperty property="userName" name="user" param="userName"/>
   
    </jsp:useBean>


is equivalent to writing as below (if the string member variables names  of text fields and user dto member variables are same)


 <jsp:useBean id="user" class="org.gp.gpr.dto.User" scope="request">
    <jsp:setProperty property="userName" name="user"/>
   
    </jsp:useBean>


I have not understood how that shortcut works. please advise
0
Comment
Question by:gudii9
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
Comment Utility
This is a feature that is called introspection. You match the parameter of your form with the parameter of your object if they have the same name.

Here is a very old (but still perfect) link that explains introspection: http://www.javaworld.com/jw-03-2000/jw-0331-ssj-forms.html (go to page 3 to go straight to introspective magic).
0
 
LVL 7

Author Comment

by:gudii9
Comment Utility
if two or more parameter of the form same then what happens. please advise
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
I am not sure. I guess you will need to define an array, like you do with normal JSP parameters.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

743 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

15 Experts available now in Live!

Get 1:1 Help Now