Shorthand for request.getparameter
hi,
i've recently discovered the ${} shorthand for get attribute ie.
<% request.setAttribute("test","100");%>
<p>${test}</p>
where ${test} will write the value of 100 to screen. conveniently this doesn't give a null error if test is undefined. even more conveniently it seems to have some automatic kind of casting so
${test/2}
will return the value of 50.0 without the need to convert to an integer (or similar)
i was wondering if anyone knew of a similar shorthand for displaying request.getParameter() objects and/or strings.
cheers,
ben
The expression language is currently available only in attribute values.
Future versions will allow its use in template text.
shame it's not implemented yet.Ahh but it is.
EL available only in attribute values applies only to JSP1.2 containers, when using JSTL.
The "future version" is JSP2.0. That is available in Tomcat 5.
the shortcut for request.getParameter("myString");
is
${param.myString}
Check out the implicit objects available in EL:
http://java.sun.com/products/jsp/syntax/2.0/syntaxref207.html#1010522
Cheers,
evnafets
Similar Messages
-
Shorthand for request.getParameter v2
quick recap, thanks to evnafets for showing
the shorthand for
<%=request.getParameter("myString")%>
or
<%=request.getParameter("myString")!=null?request.getParameter("myString"):""%>
is
${param.myString}
cheers,
benbtw: i've tested this using resin 3 and it works fine
-
Equivalent for %= request.getParameter("input") %
I am using facelets what is the equivalent for
<%= request.getParameter("input") %>#{param.input}
-
Double type for request.getParameter
Hi , I have a page to get a parameter which is a double
I declare :
Double score = request.getParameter("score") == null ? "" : request.getParameter("score");
But I got error :
incompatible types found; java.lang.String, required:java.lang.Double.
Any idea how to solve this.
I appreciated for any solution.
Thank you very much in advance.request.getParameter always returns a string, so you'll have to convert it to a double.
Something like this:
String score = request.getParameter("score");
Double score = (score == null) ? 0 : new Double(score); -
Partner for request.getParameter?
Hello,
Does Servlet API contain any methods to add parameter to
querystring?
I have a situation where I should add key=value-pair to request
that I am forwarding to other servlet.
How can this kind of thing be handled?
There are no request.setParameter or response.setParameter methods
or I did not find them. And using request.setAttribute does not work in
this case.
Is it possible to do a own new request and fill a new
key=value-pair there ?
Can anyone help me?
Thanks,Here's an extract from the servlet spec:
Java Servlet Specification Version 2.2 39
In the ServletContext and ServletRequest methods which allow the creation of a RequestDispatcher using path information, optional query string information may be attached to the path. For example, a Developer may obtain a RequestDispatcher by using the following code:
String path = ?/raisons.jsp?orderno=5?;
RequestDispatcher rd = context.getRequestDispatcher(path);
rd.include(request, response);The contents of the query string are added to the parameter set that the included servlet has access to. The parameters are ordered so that any parameters specified in the query string used to create the RequestDispatcher take precedence. The parameters associated with a
RequestDispatcher are only scoped for the duration of the include or forward call.
i.e. you can add or override parameters by including them on the getRequestDispatcher() path. -
In WL6.1 request.getParameter returns NULL for URL parameters that exist
With the following URL, I get different results between WebLogic 4.5.1 and WebLogic
6.1:
http://phx-kmccarthy.medspecialists.net/tsweb/ParametersTest.jsp?apple=macintosh&tree&dog&country=USA
Weblogic 6.1 returns:
query string = apple=macintosh&tree&dog&country=USA
apple = macintosh
tree = null
dog = null
country = USA
WebLogic 4.5.1 returns:
query string = apple=macintosh&tree&dog&country=USA
apple = macintosh
tree =
dog =
country = USA
here is the jsp...
<%--
* ParamtersTest.jsp which shows that empty parameters are ignored in WebLogic
6.1
--%>
<%
String apple, tree, dog, country;
apple = request.getParameter("apple");
tree = request.getParameter("tree");
dog = request.getParameter("dog");
country = request.getParameter("country");
out.println("<br>query string = " + request.getQueryString());
out.println("<br>apple = " + apple);
out.println("<br>tree = " + tree);
out.println("<br>dog = " + dog);
out.println("<br>country = " + country);
%>
From the documentation on the getParameter() method:
Returns the value of a request parameter as a String, or null if the parameter
does not exist.
In my opinion, not existing and being empty are different. Also, every other web
application environment we've dealt with (including WebLogic 4.5.1) treats them
as different. If the parameter doesn't have a value, (i.e. ...&tree&dog&...) then
getParameter() returns the empty string, not null.
As a result of this we have JSPs that break when running on 6.1.
Found the solution at last. Tomcat servlet container can't handle the chunked transfer-encoding that the J2ME Wireless Toolkit uses when you call outputstream.flush() in midlet. Using outputstream.close() instead of outputstream.flush() will avoid this problem for small requests. For all the codes in the articles on Http Post in Wireless Forum, don't use outputstream.flush() and it will run perfectly - Servlet's request.getParameter(parameterName) will work fine in doPost method.
-
Request.getParameter() not working correctly for Check Boxes!
Hi,
I am writing my own custom form action in cq5.4 and I need to access the fields of my form. I have a checkbox component on my form named 'cbox' and now I want to access it.
So this is the code I'm writing in the JSP
String name = request.getParameter("cbox");
But when I fill up the data on the form and submit it.. I only get the first element of the checkbox which I had selected. So suppose if the checkbox was having some options..
a
b
c
d
and if I selected b and d then I only get 'b'.
Actually the type of the name variable must be String Array. But when I do..
String[] name = request.getParameter("cbox");
//it gives me compilation error saying cannot convert from String to String[]
I cannot understand whats happening here. Can someone help me? How do I find out that which options has the user checked?
Thanks!I think you are looking for getParameterValues().
If you read http://docs.oracle.com/javaee/1.3/api/javax/servlet/ServletRequest.html#getParameter(java. lang.String) and http://docs.oracle.com/javaee/1.3/api/javax/servlet/ServletRequest.html#getParameterValues (java.lang.String), you'll see the behavior you are seeing is as-documented. -
Retriving only hidden parameters from request.getParameter
Hi,
I want to retrive only the hidden parameters from previous JSP page into current JSP page. The problem here is that my hidden parameters in privious page are dynamically generated (parameter names are decided based on values retrived from the database) and I cannot retrive them using "request.getParameter(<parametername>)"
Can I find the parameter type (i.e. text box, text area, checkbox, radio or hidden) from the request.getParameter() or request.getParameterNames() methods? or is there any other way to find it.
Thanks in advance for any helpYou can use the getParameterNames() or getParameterMap() methods from javax.servlet.ServletRequest to get all the parameters in the request. Even if they're dynamically generated, and you don't know the names in advance, these methods will ferret them out.
getParameterMap() returns name String, values String [] pairs, so you'll have to work with String arrays to get the input out. It's got to be that way to accomodate checkboxes and other HTML form elements that can send more than one value for a given name.
I prefer getParameterMap, because I don't like using Enumerations as much. - MOD -
How to get Int value from request.getParameter()?
Hi all,
I have a integer value which is passed from one page to another page.
i am geting this value in the next page using
request.getParameter().
Eg.
Suppose value of "i" in page1 is 32, i pass this as hidden variable to next page.
<input type="hidden" Value="<%=i%>" NAME="limit">
in page2, i fethch this value to a variable by name "limit"
String limit=request.getParameter("limit");
but, since value stored in limit is int, i can't assign it to string.
i can't use request.getParameter for int values.
How to solve my problem.
I know it is simple,
Pls. help me
Regards
ASh
String limit=request.getParameter("limit");String limitSTR = request.getParameter("limit");
int limit = -1;
if (limitSTR != null) limit = Integer.parseInt(limitSTR); -
Null value in Session vars and request.getParameter
We're migrating our application from iPlanet.
Under iPlanet, when we looped through a resultset and set the values to
session variables - it worked fine, even when a resultset value was null,
but in WebLogic, I get the following error:
java.lang.IllegalArgumentException: key/value is null
Is there anyway to "turn this off" so it behaves like iPlanet?
My second question is that we have many JSP's that check to see if a
parameter is null in javascript:
Here's the code:
function onLoad() {
document.form.elements[0].focus();
// Check to see if the user is coming from a shortcut
var imageName = "<%=request.getParameter("imageName")%>";
if (imageName == "null") {
selectTop("<%=select_image%>");
} else {
selectTop(imageName);
<% if (tableIndex == 2) { %>
loadShortcutIcon(13,100);
<% } %>
in iPlanet, when the parameter "imageName" is not in the URL, the javascript
variable gets set to "null" - but in WebLogic, it is set to a blank string -
"". Is there anyway to make this return null like iPlanet?
Thanks,
Matt
Hi,
the URL parameter is added just for the request to the page. When you press the command button then you issue a new request that does not have a URL parameter added. To work around this, you can use a PhaseListener that stores the URL request parameter in the session for later use
Frank -
Hello Experts,
I am sending a data from one jsp page to another using java script (document.form.txtbx.value = myData), on same page I cheked and got the correct value but on the next page, I am getting null vaues. I am giving my code just check out and give me suggetions..
On button click I am calling function jfun_submit(..,..,..,..)
function jfun_submit(mhCd , scheme , dhCd , dhnm , total , grantNo , noOfBill ,grossAmt , n_p , totAMT , dept , c_v , type , grossAmtQtr , addAmount , LOC , flagnext , neg_flg , neg_amt_alwd,tansend,appNosend,appDatesend , loc)
var getLink =mhCd+"|"+scheme+"|"+dhCd+"|"+total+"|"+grantNo+"|"+noOfBill+"|"+grossAmt+"|"+n_p+"|"+totAMT+"|"+dept+"|"+ c_v+"|"+type+"|"+grossAmtQtr+"|"+addAmount+"|"+"Budget"+"|"+flagnext+"|"+neg_flg+"|"+neg_amt_alwd+"|"+loc+"&Tan="+tansend+"&AppNo="+appNosend+"&AppDate="+appDatesend;
document.bill.getLink.value= "";
document.bill.getLink.value = getLink; //setting the value to the txtfield
alert("After Set : "+document.bill.getLink.value); //shows alert correctly.
var url="BillSchemeCheckX.jsp
document.bill.action=url;
document.bill.method="POST";
document.bill.submit();
{code}
and on next jsp page me writing following code
{code}
String getLink = request.getParameter("getLink");
out.println("GetLink Value : "+getLink);
{code}
the result displying GetLink value : null
Please help me outWhat is the html for the formfield 'getLink'? I am guessing you have the id parameter set which makes this bit work 'document.bill.getLink.value = getLink;' but you dont have the name parameter set so your request.getParameter isnt working.
-
Submitting request.getParameter value on page submit
I am getting the value from the request parameter as under
<%
String mod = request.getParameter("mod");
%>
Now i want this mod value to be submitted as page submits. For that i used:
<h:inputHidden id="mod_field" value="" />
Now the question is how to pass the above mod value using this hidden input? and secondly how to bind it with the property in the backing bean (say the name of my backing bean is bean.navigation) so that i can access and use the value.Hay this exception has again started showing me up.
exception
org.apache.jasper.JasperException: javax.servlet.jsp.JspException: javax.faces.FacesException: javax.faces.el.ReferenceSyntaxException: param.mod
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: javax.faces.FacesException: javax.faces.el.ReferenceSyntaxException: param.mod
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:854)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
org.apache.jsp.tsheetRcode_jsp._jspService(tsheetRcode_jsp.java:344)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198)
root cause
javax.faces.el.EvaluationException: javax.faces.FacesException: javax.faces.el.ReferenceSyntaxException: param.mod
com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:206)
com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:154)
javax.faces.component.UIOutput.getValue(UIOutput.java:147)
com.sun.faces.renderkit.html_basic.MenuRenderer.getCurrentSelectedValues(MenuRenderer.java:670)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderOption(MenuRenderer.java:549)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderOptions(MenuRenderer.java:525)
com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:481)
com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:430)
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:712)
javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:616)
javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:539)
com.sun.faces.taglib.html_basic.SelectOneMenuTag.doEndTag(SelectOneMenuTag.java:505)
org.apache.jsp.tsheetRcode_jsp._jspx_meth_h_selectOneMenu_0(tsheetRcode_jsp.java:449)
org.apache.jsp.tsheetRcode_jsp._jspService(tsheetRcode_jsp.java:263)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:322)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:147)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:87)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:117)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:198) -
Servlets, request.getParameter()
How do I test a servlet in Jdeveloper
that wants a param from the calling URL, like
http://.../servlet?myparam=myvalue
via
val=request.getParameter("myparam");
I did already figure out, how to get init-Parameters, from
webtogo.ora
with
getInitParameter();
but that is not what I want, I want normal
parameters.
Running my servlet within jdev pops up
a page with WebAppRunner.html in my Browser,
that calls the servlet in jdev, I even tried handcoding my param there with no succes
so far.
Thanks for any help in advance.
Rx
nullHi Ganesh,
Rx can u help me out on this.
I have an applet that access a servlet and fetches information
via a vector. The applet also sends the information via vector
back to the Servlet. But the servlet fails to write into the
database.
Thanks in advance!!!Thank you for your confidence,
I'm sorry for not being able to answer your question right away.
* You might post some code examples,
hopefully reduced to the minimum of what is
needed to understand your problem.
* You should consider opening a new thread
as your problem seems only loosly related
to mine.
* I am just an Oracle JDeveloper user having
gained some experience with jdev and the bc4j framework, but without the insight
of the sourcecode.
* You can however expect the people from
the Oracle JDeveloper Team to be more
responsive to user questions. - My general
experience is, that the responsiveness
in open source projects forums/mailing lists/newsgroups is much better. - They should be interested in their user's problems.
Rx
null -
JSP request.getParameter bug
i try the following code for receive Parameters from jsp.
<% String name=request.getParameter("Name"); %>
but when Name TextField(in HTML) is empty and i want to check
for none empty field with (if) instruction with following code..
if(name ==null ) //somecodes..
this instruction not run and programs continue .It's not a bug.
<%
String name=request.getParameter("Name");
if (name == null) {
//what to do if parameter does not exist
//e.g.: a checkbox not checked
} else if (name.trim().equals("")) {
//what to do if parameter exists but is 'empty'
//e.g.: an text input field with no non-whitespace characters
//NOTE: if you want leading and trailing spaces to be
// considered values, remove the .trim() from the condition
} else {
//there is a value.. do with it as you will
%> -
Jsp request.getparameter doesn't get querystring values
We have recently deployed our jsp application which was running successfully on ias8i apache jserv into the 8.1.7 JVM and configured the mod_ose on the Oracle HTTP server every thing seems to be fine except the following case.
Here we are accepting the userid,password from a jsp and submiting to the same jsp for action on submit we are reading a combination of jsp form feilds and url querystrings strangely we are able to get values only for the form feilds and querystrings return null.
The same peice of code works fine on apache jserv implementation.
Any clues please write to me.
<SCRIPT Language="JavaScript">
function check_password()
document.Login.action ="problem.jsp?tab=YES&nSessionId="+document.Login.sessionid.value+"&nUserId=" + document.Login.userid.value;
document.Login.target = "_top";
document.Login.method = "post";
document.Login.submit();
</SCRIPT>
<%
userid = request.getParameter("userid");
password = request.getParameter("password");
tab = request.getParameter("tab");
%>
<form name="Login" Border="0" TopMargin="0" LeftMargin="0" Marginheight="0" Marginwidth="0">
<table>
<tr>
<td class="FORMHEADERLEFTB"><b> Login</td>
<td class="FORMHEADERLEFT">:</td>
<td><input TYPE="TEXT" NAME="userid" SIZE="25" VALUE="<%=userid%> MAXLENGTH="10"></td>
</tr>
<tr>
<td class="FORMHEADERLEFTB"> Password</td>
<td class="FORMHEADERLEFT">:</td>
<td><input TYPE="password" NAME="password" SIZE="25" VALUE="<%=password%>" MAXLENGTH="10" onChange="check_password()"></td>
</tr>
</table>
<input type="hidden" name="sessionid" value="999999">
</form>
Thanks
suresh
nullHow are you retrieving the parameter values? I am able to retrieve parameters successfully using the following simple testcase:
untitled1.jsp:
<form method="post" action="servlet1">
<P>Username:
<input type="text" name="un"/>
</P>
<P>Password:
<input type="text" name="pw"/></P>
<P>
<input type="submit" value="Submit"/>
</P>
</form>
servlet1.java: (copy and paste from doGet() to doPost() method depending on value of form method in untitled1.jsp)
String un = request.getParameter("un").toString();
String pw = request.getParameter("pw").toString();
out.println(un);
out.println(pw);
Please test this and let me know your results and the differences with what you are trying to do.
Regards,
Lynn
Java Tools Team
Maybe you are looking for
-
I just downloaded firefox about a week ago and the first day i used it i went on to tumblr, and i logged in just fine. But now a week later i'm trying to log into my tumblr and it says it's loading but then it goes straight back to the log in page. I
-
Basic Questions - capturing miniDV, exporting to DVD?
I apologize for the basic questions, but it's been a while since I've done this start to finish...like five years. I shot a bunch of miniDV sports footage on a Canon GL2 and I am digitizing the footage via firewire (straight from my camera to my comp
-
What is the model number of Galaxy Nexus?
I'm trying to order a cover for my Galaxy Nexus and I'm finding a lot of cases that say Galaxy Nexus but they also have model numbers (i515, i9250). I searched google, checks the 'About Phone' section in settings but still can't figure out the m
-
SSL handshake failed: X509CertChainIncompleteErr
I am trying to send name-value pairs using https and JSSE. I am using JDev 9i, and first I create a war file and bundle JSSE with it, then deploy it to an ear file, and use Enterprise Manager of 9iAS Rel2 to deploy the ear file to the server (on Wind
-
Dme file not created - france rffof__v rffof_v
Hello all, when executing a payment through F110 (program RFFOF__V for France) the DME file is generated with no apparent error message in the payment run log. Is there any additional customizing necessary for France that is not needed in Germany or