kan tao

Greenhorn
+ Follow
since Jul 09, 2010
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kan tao

Thanks for the replies ... i was confuse with the CLASSPATH ...i hope it will work now
13 years ago
How can i solved the compile error: Cannot find symbol for the following codes

symbol: class test2
location: test.test3
test2 aa = new test2();




I'm trying to instantiate test2.java in test3.java

Both the files are in C:\MyJavaProg\test

My java path is set to C:\Program Files\Java\jdk1.6.0_06

test2 code:

test3 code:


13 years ago
Servlet B



Servlet A



I have even try using forward but still its not working.

Below is the link where i was discussing the issue :

http://www.java-forums.org/java-servlet/30663-retaining-value-checkbox-when-returning-back-servlet.html
13 years ago
Thanks for the reply everyone...


hi Michael Angstadt

Thanks for the reply. But i got another issue now ..

this code is suppose to save the session id and send to "servletA" where i can retrieve the session data through

But somehow its not working and returning NULL always. Can you point out where i'm doing it wrong??
13 years ago
i got the idea of Httpsession but now my prob is the display part.

Here is some section of my code:

servelt A



servlet B




So when the submit button Back is press, How to retrive the session value in Servlet A and retain the checked value [display those checked boxes as checked]??
13 years ago
hello,

I'm trying to retain the value of the checkbox when returning to the same servlet from another servlet. How can i implement it.

Scenario:

Servlet A has checkbox which post to servlet B then i want to go back to servlet A again and modify the checkbox that i selected before.


So how do i maintain the previously selected checkboxes [i want the checkbox to be checked when it reloads] ???

P.S. Hope my explanation is understandable.
13 years ago
Thanks Michael Angstadt


It was due to the space before "item \".
13 years ago
Thanks for the advice .... here is my code with tags


13 years ago
I have search almost everything but still i cant solved the problem.

I'm just trying to print the parameter return from the checkbox but its showing NULL every time [for the checked box ]. In the following code getParameterMap is printing the correct value but getParameter and getParameterValues both returning NULL

following is my code :

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class CheckboxTest extends HttpServlet
{

public void doGet (HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><HEAD><TITLE>Enjoy Shopping</TITLE>");
out.println("</HEAD>");
out.println("<BODY >");
out.println("<br><br>");
out.println("<P align=center><BIG><BIG>Choose the item to buy</BIG></BIG></P><br><br><br>");
out.println ("<form action=\"/demo/checkboxtest\" method=\"post\">");
out.println ("<div align=\"center\"><br>");
out.println ("<input type=\"checkbox\" name=\"item \" value=\"Item 1\" > Item 1 <br>");
out.println ("<input type=\"checkbox\" name=\"item \" value=\"Item 2\" > Item 2 <br>");
out.println("<input type=\"submit\" value=\"Add to Cart\">");
out.println ("</div>");
out.println ("</form>");
out.println("</BODY></HTML>");
out.close();
}

public void doPost (HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
PrintWriter out = response.getWriter();
try
{

Map paramMap = request.getParameterMap();
Object[] keys = paramMap.keySet().toArray();
String[] values = new String[keys.length];

for(int i=0; i<keys.length; i++)
{
values[i] = ((String[])paramMap.get(keys[i]))[0];
out.println(keys[i]+" -> "+values[i]+"");
}

String it = request.getParameter("item");
out.println(it);

String[] item = request.getParameterValues("item");
if (item != null)
{
for (int i = 0; i < item.length; i++)
{
out.println (item[i]);
}
}
else out.println ("none");

}
catch (Exception e)
{
e.printStackTrace();
}
}
}
13 years ago