Solved

jstl getting parameters

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

756 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