File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes problem with urldecoder in doGet mehtod Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with urldecoder in doGet mehtod" Watch "problem with urldecoder in doGet mehtod" New topic
Author

problem with urldecoder in doGet mehtod

sridhar dv
Greenhorn

Joined: Aug 09, 1999
Posts: 2
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);
}
}

------------------
Patricia Fulk
Ranch Hand

Joined: Sep 10, 2001
Posts: 62
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with urldecoder in doGet mehtod