User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JSP section within the Web Development category of DaniWeb, a massive community of 375,221 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,200 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JSP advertiser: Lunarpages JSP Web Hosting
Views: 1442 | Replies: 4 | Solved
Reply
Join Date: Apr 2008
Posts: 3
Reputation: Lum1n0us is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Lum1n0us Lum1n0us is offline Offline
Newbie Poster

Passing parameters between jsp pages

  #1  
Apr 9th, 2008
Hi all,

I'm a novice at using jsp and web design in general and have been trying to pass parameters between pages for a good few hours now but to no avail...

Furthermore my classification of the problem may be inaccurate, please understand that I've only been using jsp pages for about a month now.

In short, I'm trying to obtain input from a user via a textbox, then pass that value to another jsp page and my code goes something like this:

I try and retrieve the value entered by the user as follows:
out.println("<tr>");
out.println("<td>&nbsp;&nbsp&nbsp;Please enter your surname</td>");
out.println("<td><input type='textarea' name='sSurname' ></td>");
out.println("</tr>");	

I try and call the new link with the parameters as follows:
out.println("<a href = 'newuser.account.created.jsp?sName='+sName.value+''> Create Account man</a>");


When using request.getParameter(sName) on the next page no value is returned unless I physically hardcode the value of sName in the code snippet above.

Any advice would be appreciated,
Thanks alot.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 94
Reputation: Thirusha is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 9
Thirusha Thirusha is offline Offline
Junior Poster in Training

Re: Passing parameters between jsp pages

  #2  
Apr 9th, 2008
I too am new to jsps, but i do know that u will have to submit the form. use a submit button.

your code should look something like this
<form name="testform" id="testform" method="post" action="/yourjsppage.jsp">
<input type ="text" name="username" id="username" />
</form>
<input type="submit" name="submitme" value="submit" />

the text that u entered in username will then get posted to the next jsp page and the url will then look something like 'yourjsppage.jsp?username=blahblah'

On the next page u will be able to use request.getParameter() to get the value of the text field.

Hope this helps
Reply With Quote  
Join Date: Apr 2008
Posts: 3
Reputation: Lum1n0us is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Lum1n0us Lum1n0us is offline Offline
Newbie Poster

Re: Passing parameters between jsp pages

  #3  
Apr 9th, 2008
Thanks for taking the time and effort to respond, perhaps I should try and incorporate your advice into the code. Web design is pretty new to me coming from a C++/java background. The whole notion of client side/server side scripting is slowly beginning to make sense though...

At present:
I've used a javascript function that uses getElementById and then opens the page in a new window (it's probably not ideal but it served as a start I guess).

In any case, for those who are interested, here's the js function in the head section of my webpage:

<script type="text/javascript">
function myfunction() {
   var email = document.getElementById('emailtextarea').value
   var link = "user.details.found.jsp?sUserEmailAddress="+email;
   window.open(link);
}
</script>

Here's the code in the jsp tags:

out.println("<a href = javascript:myfunction(); style='color:#FF5F00;'>  Email me my login details</a>");

So after I enter an email address and click on the link, my information gets passed onto the next page which is opened in a new window. I guess the next step involves opening the link in the current window instead of opening a new one.

Kind Regards,
lum1n0us.
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,732
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 323
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Passing parameters between jsp pages

  #4  
Apr 9th, 2008
Considering that you are ready to learn, you need to look at some good tutorials posted at Suns' J2EE site which has everything you need to know about JSP's and much more. They also have a sample application which will serve as a good reference. A good book like Head First Servlet's and JSP's should make you more than an expert on the topic though and is a must read once you grasp the basics.
Last edited by ~s.o.s~ : Apr 9th, 2008 at 1:55 pm.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Apr 2008
Posts: 3
Reputation: Lum1n0us is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Lum1n0us Lum1n0us is offline Offline
Newbie Poster

Re: Passing parameters between jsp pages

  #5  
Apr 11th, 2008
Thanks for the web reference; I've managed to invest some time in reading over some of the introductory tutorials. If anything I'm beginning to understand the fundamental purpose and suited usage of jsp pages. Will most probably continue to learn on a gradual basis and hopefully become proficient in time to come.

Kind Regards,
lum1n0us.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JSP Marketplace
Thread Tools Display Modes

Other Threads in the JSP Forum

All times are GMT -4. The time now is 3:33 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC