Escapse url GET parameters in URL with Java/ICEFaces - java

I have a JAVA with JSF/ICEFaces application. I need to pass parameters from one page to another so I user something like:
<f:param name="eventName" value="#{item.event_name}" />
And then get it in the constructor using:
eventName = request.getParameter("eventName");
While works fine unless there is a '/' character in the string submitted, it doesn't get parsed properly. I believe I need to escape the '/' parameter with %2F and then parse it back.
Two things:
1- How to do this in ICEFaces or JSF
2- Are there other parameter I have to escape?
Thanks,
Tam

<h:outputLink value="http://google.com">click
<f:param name="eventName" value="#{param.eventName}" />
</h:outputLink>
works for me - the browser takes care of url-encoding.
Note that you can get request parameters directly in your page, using #{param.paramName}

Related

Struts 2 Page Include Access Request Object Attribute From Property Tag

I am including a JSP page using the s:include tag:
<s:include value="/WEB-INF/jsp/centers/tpa/admin/users/UserEmployerAccessRow.jsp" />
I have several objects that I want to make available to this include and I am trying to store them into the request before the include happens. I am using the s:set tag to store to the request object:
<s:set var="employer_tmp" value="employer" scope="request" />
Everything in the jsp works as expected up to this point. The included jsp is not able to access objects in the request from a s:property tag. Here is what I have inside of the UserEmployerAccessRow.jsp:
<s:property value="#request[employer_tmp]" />
I have also tried it this way:
<s:property value="#employer_tmp" />
I have verified that the object is in the request by doing this:
<% out.println(request.getAttribute("employer_tmp")); %>
My guess is that the s:property is looking for the internal map that Struts sets up for the request and not looking at the actual request object. Does anyone know any markup to force the s:property to grab something out of the request object? It seems like overkill to have to run another action in the loop that I have this include in. I cannot use s:param to hand parameters to the include because it only handles simple http parameters and not objects. Thanks in advance for any direction you guys can provide!
I ended up finding the problem. The attribute name needs to be quoted in the s:property tag:
<s:property value="#request['employer_tmp']" />

using # in URL as value key

My java server works as follows:
http://locahost:5555/?search="java"
The above link would work fine. However, if I ever want to use "#" as part of search string, it all goes wrong. For example:
http://locahost:5555/?search="c#"
For some reason everything after "#" gets ignored. If I use the decoded version of "#" it works fine again. For example:
http://locahost:5555/?search="c%23"
The system should be used by people that don't understand url encoding so they would never put %23 instead of #. Is there anyway around it?
Other than encoding it there is no way around it. More over the string after # treats as the location of the URL.
String after # will not be passed to the server through GET parameters. Use POST method instead.
https://developer.mozilla.org/en-US/docs/Web/API/Window.location
the user supposedly should not access the url directly so if they put "c#" in the url there would be no process on the other hand you could use
<form action="yourcontroller" method="post">
<input type="text" name="txtSearch" />
<input type="submit" value="search"/>
</form>
with this, it will take care of the special characters like "#" you mentioned.
don't forget to catch the parameter in your controller
request.getParamter("txtSearch");
It is in the browser. The server never gets a request with the hashtag (#) symbol, just up to the symbol.
A javascript workaround is probably a bad idea.

Websphere Commerce-TypedProperty

Can anyone help me to understand the usage of TypedProperty in websphere commerce?
ie,How to pass values from one jsp to other using TypedProperty without a command class.I would prefer to handle it in my client side itself without invoking Command class..can anyone help me to sort out it?
Typed property is usually used to pass values from controller commands to JSPs. If you just want to pass values from one JSP to another, create a form in your first JSP and submit it to the second.
If this is a form submit, set the values you need to pass in element. In the results jsp you can get those values using ${WCParam.xxx} .
FYI - To list out all the values in WCParam object try to print the below in JSP :
${WCParamValues}
We use typedProperty when we need to send anything from the command. For example, you give an order ID from the first JSP and want to get the final amount to be passed the result JSP. Here in the command we use the orderID from the request object -> Then we use the OrderAccessBean to get the OrderTotal -> then we set this to a TypedProperty object -> we then set this TypedProperty object to request properties using setRequestProperties() OOB method in a controller command.
Hope this makes it clear !
TypedProperty is a class in Java which can be compared to Hashmap in Java for better understanding. It is a name value pair combination.
I just wanted to understand the problem before answering further.
Why do you want to use TypedProperty in Jsp to pass the value from one jsp to another?
Are you importing the second jsp or including the second jsp to which you have to pass the values to?
If you are importing, you can use c:param tag to pass the values to the second jsp.
For included jsps, the values are already available in the second JSP.
Please include code snippets to explain your problem so that it can be answered clearly.
You can pass parameters from one jsp to another by using the following code snippet:
<c:import url="child.jsp">
<c:param name="name1" value="value1" />
<c:param name="name2" value="value2" />
<c:param name="name3" value="value3" />
</c:import>
Within the child.jsp you can read the parameters by using:
<c:out value="${param.name1}" />
<c:out value="${param.name2}" />
<c:out value="${param.name3}" />
A TypedProperty is nothing but a Wrapper to HashMap. So that's nothing to do here with passing values from one JSP to another JSP. Without invoking a command, you can't pass a Java object to another JSP.
And that is the very basic of Command Framework. I would prefer to go with the first answer.

URLRewrite filter not working with multipart form

I am using tuckey URLRewrite filter having one of its rules as follows:
<rule>
<name> Proxy URL with jession ID's </name>
<note>
</note>
<condition type="parameter" name="ParamName">[\p{ASCII}]+</condition>
<from>^/([^?]*)\.htm(.*)$</from>
<to type="proxy">%{request-url};jsessionid=%{parameter:ParamName}$2</to>
</rule>
The problem arises as soon as I add enctype="multipart/form-data" to my form (which uses POST method btw). The filter is unable to rewrite url.
Any ideas how to solve this issue?
If you can change the source of the application you could modify it so that you can use the "parameter" method of extracting the JSESSIONID. By default (at least on Tomcat) the JSESSIONID will not be passed in the form post but you could modify your form to include it. For example a JSP page might look like this:
<form action="index.jsp" method="post">
<input type="hidden" name="JSESSIONID" value="${pageContext.session.id}"/>
<input type="submit"/>
</form>
Alternatively you could try and fetch the JSESSIONID from the session cookie using a different condition. I have not tried the following but imagine something like it could work for you:
<rule>
<name>Proxy URL with jsession ID's</name>
<note></note>
<condition type="cookie" name="JSESSIONID"/>
<from>^/([^?]*)\.htm(.*)$</from>
<to type="proxy">%{request-url};jsessionid=%{cookie:JSESSIONID}$2</to>
</rule>
There are other conditions you could potentially use to check whether the session id was valid (requested-session-id-valid), originated from a cookie (requested-session-id-from-cookie) or originated from the URL of the post action (requested-session-id-from-url).
I'm not sure which version of UrlRewriteFilter you are using but if you look at the "Permanently redirect incoming URLs containing jsessionid." example at the following URL you will see that the JSESSIONID is not a parameter like other POST/GET parameters are.
http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.2/guide.html
I can highly recommend using the Firefox/Firebug together to examine your POST request and headers so you get an idea for exactly what is being passed. (I'm sure there are other similar tools that do this too, Fiddler 2 etc.).

Passing customized messages from Servlet to a JSP page?

I am new to JSP and Servlets.
What i want to know is the best way to pass some customized message to client web pages.
For example suppose i have a web page say student.jsp which has a form,to register a new student to our online application.after successfully inserting all the fields of the form,
user submits the form and data is submitted to our servlet for further processing.Now,Servlet validates it and add it to our database.so,now servlet should send a message indicating a
successful insertion of data entered by end user to end user (In our case student.jsp).
So,i could i pass this type of message to any client web page.
I don't want to pass this message as URL query String.
is there ant other better and secure way to pass these type of messages ...
use request.setAttribute("message", yourMessage) and then forward (request.getRequestDispatcher("targetPage.jsp").forward()) to the result page.
Then you can read the message in the target page via JSTL (<c:out value="${message}" />) or via request.getAttribute(..) (this one is not preferable - scriptlets should be avoided in jsp)
If you really need response.sendRedirect(..), then you can place the message in the session, and remove it after it is retrieved. For that you might have a custom tag, so that your jsp code doesn't look too 'ugly'.
I think it looks like this in JSTL:
<c:remove var="message" scope="session" />
I also think that, if "message" is a Java String, it can be set to the empty string after it's been used like this:
<c:set var="message" scope="session" value="" />
Actually, it also looks like it works if "message" is an array of Java Strings: String[]...

Categories