• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp:forward - whats wrong with this code?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends,

Here is my code. when I run the application, it directly goes to the forwarded page. It does not even allow me to enter USER NAME. I am new to JSP. Please help.


[Devaka: added code tags]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must be misunderstanding the way HTML and JSP work. When a page is rendered, it does not just stop at the form. Everything is interpreted and rendered. So the forward action will be triggered any time the page is accessed. Instead, what you should do is set the form's action attribute.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"nut boltoo", please check your private messages for an important administrative matter.
 
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please put the forward tag in some conditional tag (c:if) so that it should not be executed every time.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Harpreet Singh janda wrote:Please put the forward tag in some conditional tag (c:if) so that it should not be executed every time.

That's not going to help. The forward is in entirely the wrong place... conditionalizing it won't make it any more right.
 
Hasan Habib
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have tried to solve using a IF condition and its not working. I tried to set ACTION attribute and its not working as well. Can some one come up wit h a solution?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I tried to set ACTION attribute and its not working as well.


Show us what you've got.
 
Hasan Habib
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%
String username = request.getParameter("usernmae");
%>
<form action="<%if (username != null) {%>
<jsp:forward page="middle.jsp"/>
<%}%>" method ="get">
<input type ="text" name="username" size="25"/>
<input type="submit" value="Submit"/>
</form>

Its not forwarded.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hasan, I strongly recommend you to learn about HTML/Http first. Don't rush to using JSP and JSTL until you understand the concepts of request, response, session, HTML forms... Forget about the forward tag. Your code should look something like this (may depend on where middle.jsp is):

 
Hasan Habib
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Christophe,

Thanks for your reply. The html code you sent will take me to middle.jsp upon pressing submit button. This is fine. But I am wondering how to embed jsp:forward. I am sorry being so novice. but I need to understand
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As already pointed out, forwarding has no place in this scenario.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic