• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:forward - whats wrong with this code?

 
Hasan Habib
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"nut boltoo", please check your private messages for an important administrative matter.
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As already pointed out, forwarding has no place in this scenario.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic