Forums Register Login

Problem passing a value from one jsp to another using href

+Pie Number of slices to send: Send
Hi,

I have three pages as shown in the code below. The header.html is included as part of summary.jsp and it appears at the top of the page of summary.jsp at run time.

When the user clicks on the logout link(located at the top of the portion of the summary.jsp page) I want to alert the user whether or not they really want to logout without approving the contents of the summary.jsp ( contents not shown on this page for simplycity).

I was expecting that pageName captured by the href link code shown under header.html gets passed to logout.jsp but I see null value instead of value of "lcSum". Please give me some idea why I am seeing null value of pName in logout.jsp page.




I also tried the following approach:



I get compilation error saying that value should be in quotes. I tried using = sign as shown below, but still get the same error.


I hope to hear from experts of this great java ranch website which has been very helpfull to me. Besides that unlike other websites I get quick and prompt response/solution on this java ranch.
+Pie Number of slices to send: Send
Try:
+Pie Number of slices to send: Send
Better yet, try fixing the "href" attribute in the anchor tag.

Problems like this are easy to diagnose by simply looking at the request that's being sent.
+Pie Number of slices to send: Send
Thank you guys for quick reponse/suggestion.

Actually I had left out logout between anchor tags. In the actual code it is there. Anchor tag syntax looks right. Please let me know if the syntax is not correct.

Once again this is what I tried. I still get null value in logout.jsp.


I tried other approach as:

This is what I get:

+Pie Number of slices to send: Send
What makes you think the JavaScript in your "href" attribute is executing? I suggested fixing it for a reason, and *looking* at the request being made for a reason.
+Pie Number of slices to send: Send
Notice that I changed "'pageName" to 'pageName' (double quotes to single quotes)
+Pie Number of slices to send: Send
And use the JSP EL instead of a scriptlet to get the parameter value--once you're actually sending a parameter.
+Pie Number of slices to send: Send

I tried code shown below. It does pick up the value as shown in URL and does prompt OK. But logout.jsp does not get executed and instead I see Page Not Found Message.

.

I also tried the code without javascript as shown in the code block. I do see logout.jsp page displayed with URL shown in the code block but I do not see the value being passed to logout.jsp.



As far the other approach, whether we use single quote or double quote the compilation error is still the same.

Thanks,
Prabhakar
+Pie Number of slices to send: Send
You'd want to URL escape the value you're sending to the page. How familiar are you with how HTML, HTTP, and JavaScript work?
+Pie Number of slices to send: Send
David,

I am more compfortable doing server side programming and JDBC programming than presentation tier programming. In my job I have to do all of these. I am learning presentaion tier side programming. My pages aren't pretty.

I will read about URL escape thing and will try your other suggestion of using JSP EL in the java bean approach. As I said before use of single quotes instead of double quotes as suggested by Tom Reilly does not make the difference(still get same compilation error)

Prabhakar
+Pie Number of slices to send: Send
1. JSP expressions should NOT end with a semicolon!
You must use double quotes for the pageName String in the expression because it has to be valid Java code (single quotes won't work).

2. Try removing the spaces from the URL:

3. If your application uses sessions, you should use the response.encodeURL() method with your links. Otherwise, clients who do not support cookies will not be able to use your site.
The trouble with your code is that part of the URL is generated using Javascript, which causes problems with this...

4. You should use EL and JSTL instead of scriptlets...scriptlets are bad practice.
+Pie Number of slices to send: Send
Michael,

Thanks for your guidance. The numbers shown below corresponds to your number.

1. JSP expressions should NOT end with a semicolon!

I tried without the semicolon but still get the same compilation error.



2. Try removing the spaces from the URL:

You are right, removing spaces in the URL works. I was able to see the value TEST in the logout.jsp


3. If your application uses sessions, you should use the response.encodeURL() method with your links. Otherwise, clients who do not support cookies will not be able to use your site.

I am using Request scope (not session). I will keep in mind your point in case I chose to use sessions.

4. You should use EL and JSTL instead of scriptlets...scriptlets are bad practice.

I tried the code shown by you under this and I get the message shown below. I think that is because when I installed Oracle JDeveloper tool I did not select JSTL.

The tag library http://java.sun.com/jsp/jstl/core is referenced but not installed.
The prefix C is never used.

I'll look into it.

5. Lastly, I tried the code in the code block removing spaces as suggested by you. The problem of "The webpage cannot be found" still persist. This confirms your thinking that the Javascript in that URL causing the problem of not displaying logout.jsp page.



The question is how to make the code in #5 and/or # 1 above to work. I am using code #1 to pass the pageName value to logoutBean where I can check its value and disconnect the database (JDBC) connection depending on user response to the prompt - 'Are you sure you want to logout without approving'.




+Pie Number of slices to send: Send
1. Actually, try this...you can assign a request parameter to a bean property using the "param" attribute.

5. Try changing "/logout.jsp" to "logout.jsp":
+Pie Number of slices to send: Send
Bad idea. All URLs in a web application should be server-relative. That is, starting with / and the context path.
+Pie Number of slices to send: Send
(And it gets even worse once pages are made up of components, and your JSPs live in a more reasonable place (under /WEB-INF) and are never accessed directly.
+Pie Number of slices to send: Send
David,

I am using Jdeveloper to develop the application with default OC4J server. During the development when I create a JSP or HTML it automcatically puts it in the dirctory shown in the code block


The only file that goes into WEB-INF is the web.xml.

But When I create WAR file using Jdeveloper and I deploy WAR file on to TOMCAT server running on C drive. All *.jsp and *.html goes into the TOMCAT directory path shown below.


One other point is that I tried running just the header.html (by itself-outside of summary.jsp) but I still see the same message "The webpage cannot be found" message. "
Thanks,
Prabhakar

Michael,

I tested the setProperty code you suggested I still get the "The webpage cannot be found" message." Without the execution of logout.jsp page the code in the code block below will not be executed.

I think once we get the logout.jsp page to display everything else will go smooth. Your thinking that javascript is causing the problem is still correct.

Shown below is the OC4J log when I click on "logout' link. Just a note that I was seeing this same log content before as well.


David/Michael,

Please let me know your answers to the following questions:

1. Is there any other way (other than use of javascript) we can assign value of variable pageName in that href link?

2. I don't know much about CSS, can it be used to assign value to the pageName in that href link?

3. Is there any other way we can let logoutBean know user is trying to logout?

3. What if I use header.jsp instead of header.html? will it solve the problem?

Thanks,
Prabhakar
+Pie Number of slices to send: Send
So your development environment looks like:

And your deployment environment looks like:

So what URLs are you using to access the files? They should be something like:
http://localhost:8080/lcCalc/header.html
http://localhost:8080/lcCalc/logout.jsp
http://localhost:8080/lcCalc/summary.jsp

Kaverappa Prabhkar wrote:1. Is there any other way (other than use of javascript) we can assign value of variable pageName in that href link?


I thought pageName cam from a textbox, but looking again I see that it doesn't. You don't have to use Javascript to build the link because its value isn't entered on the client-side by the user. Use a include standard action instead of an include directive and pass the pageName via a parameter. You have to turn header.html into a JSP:


Kaverappa Prabhkar wrote:2. I don't know much about CSS, can it be used to assign value to the pageName in that href link?


No

Kaverappa Prabhkar wrote:3. What if I use header.jsp instead of header.html? will it solve the problem?


See above.
We don't have time to be charming! Quick, read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 30197 times.
Similar Threads
session problem
JSP Logout
How to make a JSP/HTML page to stay on itself when user clicks on back button on the browser?
javascript code is not called in jsp page
using the value of a session variable
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 03:40:51.