This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes popup form - howto get data ? from newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "popup form - howto get data ? from newbie" Watch "popup form - howto get data ? from newbie" New topic
Author

popup form - howto get data ? from newbie

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi,good day, everyone ,i want to keep user setting values from popup form(multiple pages), can anyone guide me how to get alll data that user select or keyin in popup form in jsp ?...thank you very much for helping !!
[ September 28, 2004: Message edited by: Alvin chew ]
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
What's a popup form? Is this to do with JavaScript?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
chen hongyun
Greenhorn

Joined: Sep 23, 2004
Posts: 3
you can do it like this
page1.jsp:
<html>
<head><b>session 1</b></head>
<body>
<%
String emailbutton = (String) session.getAttribute("emailbutton");
%>
<form name="form1" method="post" action="page2.jsp">
email : <input type="text" name="emailbutton" value="<%= emailbutton%>">
<input type="submit" name="Submit" value="call">
</form>
</body>
</html>

page2.jsp:
<html>
<head><b>session 2</b></head>
<body>
<%
session.setAttribute("emailbutton",(String) request.getParameter("emailbutton"));
String emailbutton = (String) session.getAttribute("emailbutton");
String emailbutton2 = (String) sessin.getAttribute("emailbutton2");
%>
<form name="form1" method="post" action="page3.jsp">
<%
out.println("we get emailbutton:" + emailbutton + " from session");
%>
job : <input type="text" name="emailbutton2" value="<%= emailbutton2%>">
<input type="submit" name="Submit" value="call">
</form>
</body>
</html>
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
thank you, chen , thank you very much for your time and help ...

i have a question, when i type as follow



it generate error (can't get variable), why is it so ? but if i put "String email2" then is ok ...is it a need to follow exactly the name from getAttribute("email2")?

thank you !
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
How are you setting your attribute. i mean, if you set like this

request.getSession().setAttribute("email2","any");

then you must get like this

session.getAttribute("email2");

if it is like

request.getSession().setAttribute("String email2","any");

then you must get like this

session.getAttribute("String email2");
[ September 27, 2004: Message edited by: adeel ansari ]
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
thanks for reply adeel , what i actually means is as follow



why i must make email2 then only can prone the error ? i try "String email = (String) session.getAttribute("email2");" , it come up "can't find the variable " error, thank you !
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
may be your session doesn't have this "email2" attribute. try to get session.getId(). and confirm it that you are accessing the same session, while doing getAttribute().

infact couldn't get you really elaborate more if it is something different. give a snippet of setAttribute() along getAttribute()
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, dirk, this is actually jsp question

i would like to further my description on this popup

when the popup form display, it actually contains 3 pages, i named it page1, page2 and page3 ..every page contains some textbox and selection for keeping user configuration setting

each page contains "previous" and "next" button, and when user click next button it will goto page2 while user in page1.. and also page2 next button will go page3, however, page3 contain extra button "preview" which allow display user selected data

now, i want to display selected data when user click "preview" button in page3, and these selected data also be save and use for further process

can anyone please suggest or guide me on my case ? thank you very much for your time !!
chen hongyun
Greenhorn

Joined: Sep 23, 2004
Posts: 3
you can save selected data in HttpSession when user click "next"
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
do you mind to show me how to do that ? i'm new in jsp ...thank you for your time
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
request.getSession().setAttribute("page3", data);
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
this is setsession2.jsp


<html>

<head><b>session 1</b></head>



<body>



<form name="form1" method="post" action="setsession.jsp">

email : <input type="text" name="emailbutton" >


<input type="submit" name="Submit" value="call">

</form>

<%
String mybutton = request.getParameter("emailbutton");
System.out.println("emailbutton:" + mybutton);
session.setAttribute("accessobj2", mybutton);
%>

</body>
</html>

[ September 28, 2004: Message edited by: Alvin chew ]
[ September 28, 2004: Message edited by: Alvin chew ]
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
this is setsession.jsp

<html>

<head><b>set session 2 </b></head>

<%
session.setAttribute("accessobj", "testing");
%>


<body>



<form name="form18" method="post" action="getsession.jsp">

email : <input type="text" name="emailbutton2" >


<input type="submit" name="Submit2" value="call">

</form>




<!-- <a href="getsession.jsp"> get session </a> -->




</body>


</html>
[ September 28, 2004: Message edited by: Alvin chew ]
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
this is getsession.jsp

<html>

<head>set session</head>


<body>

<%


String str = (String) session.getAttribute("accessobj");
String str1 = (String) session.getAttribute("accessobj2");

String str2 = (String) request.getParameter("emailbutton");

if(str == null)
{out.println("null");}

else

{out.println("we get :" + str2 +" from getParameter");}

{out.println("we get :" + str +" from session");}

{out.println("we get :" + str1 +" from session");}
%>


</body>


</html>
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
from getsession.jsp , how do i get the values that type by user ? say "emailbutton" and "emailbutton2" text field ....thank you !!
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
hi, this is the source code that i mentioned, if i put "String email" as shown, it will generate error ? why is it so ?

Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
anyone think i did wrongly ...i think may be cause by p2p software like edonkey s/w
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
you mean if you do this,

<%String email = (String) session.getAttribute("email2");%>

then it results in error "can't find the variable"

and if you do this instead,

<%String email2 = (String) session.getAttribute("email2");%>

then it works fine.

i dont think so. could you print the whole StackTrace??
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
how to print stacktrace ? adeel ?
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
this is the error i get from tomcat server ..

The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 29 in the jsp file: /jsp/setsession.jsp

Generated servlet error:
[javac] Compiling 1 source file

C:\jakarta-tomcat-5.0.12\work\Catalina\localhost\jsp\org\apache\jsp\jsp\setsession_jsp.java:69: cannot find symbol
symbol : variable email2
location: class org.apache.jsp.jsp.setsession_jsp
out.print(email2);
^
1 error


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:128)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:351)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:413)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:437)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:291)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)


note The full stack trace of the root cause is available in the Tomcat logs.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
wht you gettin is a compile time error or a runtime exception??

if exception then do e.printStackTrace() and paste the exception from console.

otherwise, paste the error from the console.

are you using Tomcat as a JSP container?? or something else. please mention.
Alvin chew
Ranch Hand

Joined: Jan 08, 2004
Posts: 834
error is shown on upper thread
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
nothing to say. just make sure that you are using <%%> instead of <%= %>
 
jQuery in Action, 2nd edition
 
subject: popup form - howto get data ? from newbie
 
Similar Threads
Pop up URL authentication
how to get value from popup window
popup window loses variable
How to refresh the main window once we close the popup
disabling and enabling text boxes