Solved

jstl getting parameters

Posted on 2013-01-31
3
449 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
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java JRE greater than 1.6 5 62
Java Loop 6 59
servlet requestdispatcher include and forward differences 1 30
servlet filter example 37 58
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

813 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

12 Experts available now in Live!

Get 1:1 Help Now