Solved

jstl getting parameters

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
servlet and mdb, jms error 1 82
java example issue 5 67
Java array 21 150
Does it make sense to split a controller into two file 6 20
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

751 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