Forums Register Login

problem with urldecoder in doGet mehtod

+Pie Number of slices to send: Send
When i am trying to decode the urlencoded string it is not returning the
decoded string
i am sending my code please help me out with necessary changes
sridhar
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class serverListening extends HttpServlet
{
String str=null;
String temp1=null;
String ret=null,temp=null;
public void doGet(HttpServletRequest req,HttpServletResponse res)
throws IOException,ServletException,Exception
{
try{
ret=URLEncoder.encode("srikanth|sridhar|madhu|rachu|paddu|");
System.out.println(ret);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
try{
temp=URLDecoder.decode(ret);
System.out.println(temp);
}catch(Exception e)
{
System.out.println(e.getMessage());
}
}
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws IOException, ServletException
{
doGet(req,res);
}
}

------------------
+Pie Number of slices to send: Send
Hi Sridhar,
Try the following code. All I really did was use the printwriter and it seemed to be working. Let me know if this works for you.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.URLDecoder;
import java.net.URLEncoder;
public class trish extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
String str=null;
String temp1=null;
String ret=null,temp=null;
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
try{
ret=URLEncoder.encode("srikanth|sridhar|madhu|rachu|paddu|");
out.println(ret);
}catch(Exception e){
System.err.println(e.getMessage());
}
try{
temp=URLDecoder.decode(ret);
out.println(temp);
}catch(Exception e){
System.err.println(e.getMessage());
}
}
}
Trish
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1183 times.
Similar Threads
Servlet --> Connection
to enter Date in Oracle from Servlets
HashTable in Servlet!!
i can't understand this sentence ~~please help me,thanks
help required about URLConnection
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:08:41.