Solved

jstl getting parameters

Posted on 2013-01-31
3
465 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
[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
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 38842800
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
ID: 38856182
if two or more parameter of the form same then what happens. please advise
0
 
LVL 35

Expert Comment

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

632 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