aspose file tools*
The moose likes JSP and the fly likes jsp:forward - whats wrong with this code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:forward - whats wrong with this code? " Watch "jsp:forward - whats wrong with this code? " New topic
Author

jsp:forward - whats wrong with this code?

Hasan Habib
Greenhorn

Joined: Apr 21, 2010
Posts: 5
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61227
    
  66

"nut boltoo", please check your private messages for an important administrative matter.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

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

Joined: Jan 10, 2002
Posts: 61227
    
  66

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

Joined: Apr 21, 2010
Posts: 5
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Show us what you've got.
Hasan Habib
Greenhorn

Joined: Apr 21, 2010
Posts: 5
<%
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

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

Joined: Apr 21, 2010
Posts: 5
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

Joined: Jan 10, 2002
Posts: 61227
    
  66

As already pointed out, forwarding has no place in this scenario.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:forward - whats wrong with this code?