• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with urldecoder in doGet mehtod

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}

------------------
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic