• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:forward and jsp:include

 
Muni Jampana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Muni Jampana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>");
 
Muni Jampana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've already got your answer, why are you ignoring it?
 
li bei
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Muni Jampana
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64958
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic