GeeCON Prague 2014*
The moose likes JSP and the fly likes In the messages module reply is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "In the messages module reply is not working" Watch "In the messages module reply is not working" New topic
Author

In the messages module reply is not working

naveen joyce
Greenhorn

Joined: Apr 15, 2011
Posts: 6
Hi all,

I want to send lgnid to another jsp page where in the present page im assigning like the whole table to a string result.Now i want to access lgnid in another jsp page like string lgnid=request.getParameter("lgnid");...I'm unable to to get lgnid in another page.Its giving null.Can anybody help me?

Reply.jsp

String result="<table width=100% cellspacing=1 border=0 cellpadding=0>
<form name=frmmsgreply action='' onSubmit='return validate()' method='post'>
<input type=hidden name=lgnid value='"+lgnid+"'>
<tr bgcolor=#7EB8B3>
<td width=15% bgcolor=#CCCCCC><strong>To</strong></td>
<td width=2% bgcolor=#CCCCCC align=center><strong>:</strong></td>
<td width=64% bgcolor=#CCCCCC>
<input type=text name=txtto value="+name+" size=55>
</td>
<td width=19% bgcolor=#CCCCCC></td>
</tr>
<tr bgcolor=#7EB8B3>
<td bgcolor=#CCCCCC><strong>Subject</strong></td>
<td bgcolor=#CCCCCC align=center><strong>:</strong></td>
<td bgcolor=#CCCCCC>
<input type=text name=txtsubj value='Re :"+subj+"' size=55>
</td>
<td bgcolor=#CCCCCC></td>
</tr>
<tr bgcolor=#7EB8B3>
<td bgcolor=#CCCCCC valign=top><strong>Message</strong></td>
<td bgcolor=#CCCCCC align=center valign=top><strong>:</strong></td>
<td bgcolor=#CCCCCC>
<textarea name='txtdesc' rows=6 cols=65>"+msg+"</textarea>
</td>
<td bgcolor=#CCCCCC></td>
</tr>
<tr bgcolor=#7EB8B3>
<td bgcolor=#CCCCCC></td>
<td bgcolor=#CCCCCC></td>
<td bgcolor=#CCCCCC>
<input type=submit value=Send class=username name=btnsbmt> 
<input type=reset value=Clear class=username name=btnrst> 
</td>
<td bgcolor=#CCCCCC></td>
</tr>
</form>
</table>";
out.print(result);


please help me.....................
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

Set the lgnid as request attribute in first JSP



In second JSP, you can access the request attribute using scriptlet, expression or JSP el.

Note: you need to use request attributes and not request parameters, they both are different.


[Servlet tutorial] [Servlet 3.0 Cook Book]
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi Naveen,
First of all, Welcome to JavaRanch community......... .
After looking into your code I assume that you are a newbie in Server Side Programming.Surprisingly your code snippet contains the things,should not be there,making whole the phenomenon suispected and ambigous.

String result="<table border=0 >

I think the first line in itself is an annoying thing for a server side components(JSP,Servlet) developer.Take a look at "what have you done".You are assigning a HTML tag to a String variable,which is not possible at any cost,making things worse for you double-foldedly-

1.First of all whatever you are assigning to String result should be a legel java code.
2(a).Your java code should be in Java code tags(Scriptlets,Expressions,Declarations,Directives).like for your code snippet first line of your code should be in a scriptlet,like-

If you are taking a variable from request scope(previously submitted HTML page/JSP) and assigning it to a String(Assumption).

(b).Latest recommendation of JSP will not suggest you to use Scriptlets in your JSP. Putting java code in JSP is considered a bad practice now according to a standard web application architecture(MVC) JSPs are considered good only for showing view to end users,not performing any business logic(Java Beans are used for this purpose) and servlet Servlet is responsible for taking the contents of incomming http requests and process for further forwarding to appropriate view(a JSP).
Go through this link.
Link
JSTL and EL are encouraged to use instead of Scriptlets in JSP,having several disdvantages-

1. you can't reuse scriptlets.
2. you can't make scriptlets abstract.
3. you can't make use of inheritance/composition.
4. if scriptlet throws an exception halfway, all you get is a blank page.
5. scriptlets are not unit-testable.
6. more time is needed to maintain mingled/cluttered/duplicated code logic

I would recommend you book "HeadFirst JSP and Servlet" to start with,Initially you can start with tutorial on Sun's site.

also UseCodeTags while posting your code.
also Indent your code.It makes others to easily understand your code and reply in a better way.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198

request.setAttribute("Ignig", lgnid)



Also forward the control to correct JSP using RequestDispatcher

on "another.jsp" you can fetch the value of "lgnid" like this-



Better to use JSTL or EL,making you comfertable with further releases of JSP in future.
naveen joyce
Greenhorn

Joined: Apr 15, 2011
Posts: 6
Thnx ankit for a quick response.Yeah im new bie in jsp coding.Well let me quit you full code to analyse


%>
</head>
</html>
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi Naveen,
can you use code tags.here.UseCodeTags.also indent the code properly,it makes others to read your code easily.
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi Naveen,
So what is your problem now?Are you getting the value of lgnid properly at other page?
naveen joyce
Greenhorn

Joined: Apr 15, 2011
Posts: 6
Hi ankit,

Nope.I cannot get the lgnid in the main.jsp.I have check with print statement also.Main prob is that lgnid is not coming from getReply.jsp to main.jsp.If i'm displaying lgnid in getreply.jsp with print statement i am able to display but its not coming to another page i.e main.jsp.




Thanks
Ankit Tripathi
Ranch Hand

Joined: Oct 17, 2009
Posts: 198
Hi Naveen,
You can put the "lgnid" in application scope in "getReply.jsp",in this case lgnid would be available to all JSPs' in your application like-


You can fetch it main.jsp like-



 
GeeCON Prague 2014
 
subject: In the messages module reply is not working