Two Laptop Bag*
The moose likes JSP and the fly likes jsp:forward and jsp:include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp:forward and jsp:include" Watch "jsp:forward and jsp:include" New topic
Author

jsp:forward and jsp:include

Muni Jampana
Greenhorn

Joined: May 27, 2007
Posts: 9
Hello,

I am trying to do a page where I will be able to edit student record.
I am using Servlets and JSP.
There is a "SearchResultsPage.jsp" where the student results will be displayed. When I click on the edit link in the results... I should be able to pass the relavant student id to the servlet.

When I used the following code.. In the servlet when I code
request.getParameter("sid"); its giving null. Even I am not able to get the "edit" as hyperlink.

I am using the following code:

for(int i = 0;i<al.size();i++)
{
ElementaryStudents obel = (ElementaryStudents)al.get(i);
out.print("<tr>");

out.print("<td>");out.print(obel.getFirstname());out.print("</td>");
out.print("<td>");out.print(obel.getLastname());out.print("</td>");
out.print("<td>");out.print(obel.getAddress1());out.print("</td>");
out.print("<td>");out.print(obel.getAddress2());out.print("</td>");
out.print("<td>");out.print(obel.getCity());out.print("</td>");
out.print("<td>");out.print(obel.getState());out.print("</td>");
out.print("<td>");out.print(obel.getZipcode());out.print("</td>");
out.print("<td>");out.print(obel.getEmailID());out.print("</td>");
out.print("<td>");out.print(obel.getPhone_home());out.print("</td>");
out.print("<td>");out.print(obel.getPhone_business());out.print("</td>");
out.print("<td>");out.print(obel.getPhone_mobile());out.print("</td>");
out.print("<td>");

out.print("<jsp:forward page='EditStudent.do' > Edit");
out.print("<jsp:param name='sid' value='value1' />");
out.print("</jsp:forward>");

out.print("</td>");

out.print("</tr>");


}
%>


Hope someone will help me..
Thank you soo much
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Originally posted by Muni Jampana:

I am using Servlets and JSP.


Looks to me like you are using just Servlets.

out.print("<jsp:forward page='EditStudent.do' > Edit");
out.print("<jsp:param name='sid' value='value1' />");
out.print("</jsp:forward>");


You cannot emit JSP actions from a servlet, They must be in a JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Muni Jampana
Greenhorn

Joined: May 27, 2007
Posts: 9
Hello thanks for your reply.
That is my JSP Page code in a scriplet

If its wrong can you guide me in building a Page,
Where after seeing my search results.. If I want to edit a student profile .. I should be able to click edit.. and edit his details in a different page.( I am just using servlets and JSP)

Thank you
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Then why are you using out.print at all?

The whole point of a JSP is to not have to build up markup in Java code.

Get rid of the out.print's and put the HTML markup in template text. Same with the JSP actions.

This is just one reasons that scriptlets should no longer be used in JSP pages.
li bei
Greenhorn

Joined: Jul 22, 2007
Posts: 20
change
out.print("<jsp:forward page='EditStudent.do' > Edit");
out.print("<jsp:param name='sid' value='value1' />");
out.print("</jsp:forward>");
to
out.print("<a href='EditStudent.do'>Edit</a>");


I am sorry that my English is poor.If there is something wrong with my words,please tell me .Thank you very much.
Muni Jampana
Greenhorn

Joined: May 27, 2007
Posts: 9
Thank you very much li for your responce .. but

I can change it to the anchor tag.. but what I need to do is... I should be able to pass the Student_id to the servlet so that with the help of that ID I will be again retrieving the Student Record for editing.

I had created a SearchResultsPage.jsp where Students list will be displayed. I like to add an 'edit' Functionlity to that Page.. soo that if I want to edit particular student record(which will be a button or a hyperlink beside each student record) I should be able to do that.

Please Help me.. Thank you in Adavance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

You've already got your answer, why are you ignoring it?
li bei
Greenhorn

Joined: Jul 22, 2007
Posts: 20
out.print("<a href='EditStudent.do?sid="+obel.getId()+"'>Edit</a>");

This maybe one way .

[ July 22, 2007: Message edited by: li bei ]
[ July 22, 2007: Message edited by: li bei ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by li bei:
out.print("<a href='EditStudent.do?sid="+obel.getId()+"'>Edit</a>");

This maybe one way .

[ July 22, 2007: Message edited by: li bei ]

[ July 22, 2007: Message edited by: li bei ]


Bear's earlier point (one of them) is that there is no need to build up HTML strings using Java if you're using JSP.

Why use out.println(...) and go through the trouble of escaping quotes when a simple

will do?
[ July 23, 2007: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Thats Correct. As Bear said, i think you got confused of the usages of Servlets and JSPs. There should be a clear separation and meaningful purpose of using the technologies.

In JSPs, you can very well use the HTML markup codes directly. Then why are you taking pain in emitting the markups via out.println() which are very well unnecessary and should be omitted?

What Ben Souther said is very easy and suggestable.

HtH.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Muni Jampana
Greenhorn

Joined: May 27, 2007
Posts: 9
Thank you very much for all your help. I am new to JAVA and following a book which has got the code as out.print. As I go further I will be using scriplets.
I once again thank you for your guidance and help.

BYe,
Muni
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Originally posted by Muni Jampana:
Thank you very much for all your help. I am new to JAVA and following a book which has got the code as out.print.


My advice would be to throw this book away and get a decent one. Any book that advises you to emit HTML markup from out.print statements in a JSP is ridiculous.

As I go further I will be using scriplets.


You are already using scriplets.
 
Consider Paul's rocket mass heater.
 
subject: jsp:forward and jsp:include
 
Similar Threads
page refresh problem
Virtual Host/WebGroup Not Found
what could be the reason behind this exception?
Creating Edit Profile Page in JSP
getting more dynamic in a result page