How to Modify Data in a Servlet Response
Hi..
I have a servlet that upon receving an http request from client sends some data to the client browser, but i want to modify the data that is being sent to the client and resend it somehow (like its a kind of bypassing...without sending the original data..i want to modify the data and send the response ON THE FLY.
Any ideas of suggestions how to do it, if some one of you has already done it then pls do send some code snippet.
Thanx in advance
mark.
Aha... now the truth comes out. You asked how to do it, but your secret question was that you were already doing it and you were having some problems. It's generally just better to come out and ask the question, even though it may be embarrassing that what you did isn't working.
To me, what you did sounds like a perfectly good method, except that writing the data to a temp file is going to run you into problems as soon as you get two requests at about the same time. I would do that in memory instead (write to a ByteArrayOutputStream, get the resulting array of bytes, modify it, and write the end result out to the servet response's output stream).
The problem you describe, though, is probably caused because the browsers are caching requests to your servlet. Do you have something like this code in your servlet that tells the browsers not to cache it?response.setHeader("Cache-Control", "no-cache");
response.setHeader("Pragma", "no-cache");
Similar Messages
-
How to modify Data Template ARXSGPO.xml
We are on EBS 12.1.1. My client want to customize AR Customer Balance Statement Letter. They need rtf to be modified as well as some additional info for which I need to modify Data Template ARXSGPO.xml .
But I am not able to modify above xml file. Update File button has been disabled. Could someone tell me how I can update existing xml file ?
Thanks in AdvanceHi
You could use the XDOLoader command to upload data templates.
http://bipublisher.blogspot.com/2008/01/bi-publisher-xdo-loader.html
But it would be better if you could create a custom report and attach the new date template, instead of modifying the standard report.
Regards
Nishka -
How to modify data in table control
hi
i have created table control where i have displayed data into table control
logic used
screen 200
PROCESS BEFORE OUTPUT.
MODULE SELECT_RECORD.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TBC_200'
MODULE TBC_200_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TBC_200_CHANGE_COL_ATTR.
LOOP AT IT_MARA
INTO WA_MARA
WITH CONTROL TBC_200
CURSOR TBC_200-CURRENT_LINE.
MODULE TBC_200_GET_LINES.
*&SPWIZARD: MODULE TBC_200_CHANGE_FIELD_ATTR
ENDLOOP.
MODULE STATUS_0200.
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TBC_200'
LOOP AT IT_MARA.
CHAIN.
FIELD WA_MARA-MATNR.
FIELD WA_MARA-ERSDA.
FIELD WA_MARA-ERNAM.
MODULE TBC_200_MODIFY ON CHAIN-REQUEST.
ENDCHAIN.
FIELD WA_MARA-MARK
MODULE TBC_200_MARK ON REQUEST.
ENDLOOP.
MODULE TBC_200_USER_COMMAND.
*&SPWIZARD: MODULE TBC_200_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TBC_200_CHANGE_COL_ATTR.
module -
MODULE SELECT_RECORD.
MODULE SELECT_RECORD OUTPUT.
SELECT MATNR ERSDA ERNAM
FROM MARA
INTO CORRESPONDING FIELDS OF TABLE it_mara.
ENDMODULE. " SELECT_RECORD OUTPUT
and
another thing
i have made field MARA-ERSDA. and FIELD WA_MARA-ERNAM editable by
input possible using layout
so
now those 2 fields contents are editable
i want to know how to edit and save the data
some body guide.
and i want to put the lock so that i can update
can tell how to implement lock.
Thanks
Edited by: viju bangalore on Jan 27, 2011 10:40 AMHi Viju,
In PAI do something like this
LOOP AT itab.
MODULE mod_table_control.
ENDLOOP.
MODULE user_command_0100.
at module mod_table_control put this
MODULE mod_table_control INPUT.
MODIFY itab FROM demo_conn INDEX flights-current_line.
if sy-subrc ne 0.
insert itab.
endif.
ENDMODULE.
for saving you can create at custom gui status with a save button, and at MODULE user_command_0100 save the data. -
How to modify date format for Standard Purchase Order Template XSL-FO
I am editing the XSL-FO for the Standard Purchase Order.
I need to modify the promised date column to 'DD-MON-YYYY' , tried to use substring in below line but it didn't work
<xsl:value-of select="LINE_LOCATIONS/LINE_LOCATIONS_ROW/PROMISED_DATE"/>
Any solution for this ?
thanks
PravinThanks for your response.
I tried to change the code in below format but it was giving error.
Original code
<xsl:value-of select="LINE_LOCATIONS/LINE_LOCATIONS_ROW/PROMISED_DATE"/>
modified to
<xsl:value-of select="xdoxslt:format_date(LINE_LOCATIONS/LINE_LOCATIONS_ROW/PROMISED_DATE,'dd-mmm-yyyy','dd/mmm/yyyy hh24:mi:ss',$_XDOLOCALE,$_XDOTIMEZONE)"/>
also tried with
<xsl:value-of select="xdoxslt:format_date(LINE_LOCATIONS/LINE_LOCATIONS_ROW/PROMISED_DATE,'dd-mmm-yyyy','dd-mmm-yyyy hh24:mi:ss',$_XDOLOCALE,$_XDOTIMEZONE)"/>
also tried like
<xsl:value-of select="xdoxslt:format_date(LINE_LOCATIONS/LINE_LOCATIONS_ROW/PROMISED_DATE,'dd-mmm-yyyy','dd/mmm/yyyy',$_XDOLOCALE,$_XDOTIMEZONE)"/>
Tried above 3 methods but it didn't work.
right now the date format in pdf file is 24-MAY-2011 21:56:24 i need to remove 21:56:24 and have only 24-MAY-2011
any suggestions.
thanks -
I want to parse the response content before it is displayed in the browser. I wrote a Servlet Filter to parse the request / response.
Since there are no public API s available to get the content of response, I am not sure , how to read the response.
Any idea ??Implement HttpServletResponseWrapper, override the writing methods to let them write to some reuseable/accessible buffer and access it afterwards.
-
How to modify data in the excel sheet.
Hi,
I have a requirement like ,
i have a excel file which contains only one column (all the data in the single colume )so now i have to modify that excel sheet and have to make some more columns based on my requirement.
eg:
column1
mumbaikolkata
delhichennai
mumbaikolkata
this shud be converted like this
column1 column2
mumbai kolkata
delhi chennai
mumbai kolkata
can i directly modify the excel sheet based on my requirement without using internal tables in between.
like excel ->internal table-> modified internaltable-> excel.
Edited by: Sravani Bellana on Dec 18, 2008 5:46 AMHi sravani,
true that we need to specify the rows and columns,
I have worked on such applications i shall describe the possibilities and then you can find the necessary option,
1) Function module:SAP_CONVERT_TO_XLS_FORMAT .
it needs
file path p_file type rlgrap-filename and
i_tab_sap_data (the internal table name).
2) Function module : MS_EXCEL_OLE_STANDARD_DAT
it needs
file path p_file like RLGRAP-FILENAME
data_tab (int_data "internal table with data)
fieldnames (int_head "internal table with header)
3) if the download application is a one time then go for the following option:
write the program to display the data in the internal table on the screen.
execute the program.
type %pc on the command bar and try downloading using the options displayed.
hope any one of these work out.
get back if you till have any clarificatrion
thanks
srikanth -
How to modify date format for Standard Purchase Order
In the Standard Purchase Order I have been trying to modify the date format of the Need by and Promised Date. To display DD-MON-YYYY please could some advise.
ThanksThe varaibles and prarameters I am using are.
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ora="http://www.oracle.com/XSL/Transform/java/" xmlns:xdofo="http://xmlns.oracle.com/oxp/fo/extensions" xmlns:xdoxslt="http://www.oracle.com/XSL/Transform/java/oracle.apps.xdo.template.rtf.XSLTFunctions" xmlns:xdoxliff="urn:oasis:names:tc:xliff:document:1.1">
<xsl:param name="_XDOCALENDAR">GREGORIAN</xsl:param>
<xsl:param name="_XDOLOCALE">en-US</xsl:param>
<xsl:param name="_XDOTIMEZONE">GMT</xsl:param>
<xsl:param name="_XDODFOVERRIDE">;</xsl:param>
<xsl:param name="_XDOCTX">#</xsl:param>
<xsl:variable name="_XDOXSLTCTX" select="xdoxslt:set_xslt_locale($_XDOCTX, $_XDOLOCALE, $_XDOTIMEZONE, $_XDOCALENDAR, $_XDODFOVERRIDE)" /> -
How to modify data recieved from the database and displayed in a DG
Hello, it's me again with a simple question :
i've got the SQLi request who returns multiples rows.
In this row i have for example :
Reward --> 1
How to, instead of displaying 1 in the datagrid, change this value to "YES"
I follow this lead :
private function onResultStats(event:ResultEvent):void
ServerStatsArr = new ArrayCollection(event.result.source);
for (var i:int=0; i < ServerStatsArr.length;i++)
if (ServerStatsArr[i].abonnement == 304){
ServerStatsArr[i].abonnement = 'Premium';
}else{
ServerStatsArr[i].abonnement = 'Non';
if (ServerStatsArr[i].transparence == 1) {
ServerStatsArr[i].transparence = 'Oui' ;
}else{
ServerStatsArr[i].transparence = 'Non' ;
ServerStatsArr.refresh();
Why this method is working for abonnement when (ServerStatsArr[i].abonnement == 304) it displays Premium but it's NOT working for transparence ?
i tested (ServerStatsArr[i].transparence == 1) and (ServerStatsArr[i].transparence == '1')
Thank youhi Again,
private function setLabel(item:Object,column:DataGridColumn):String
switch(column.dataField)
case "transparence":
if (item.transparence == "1")
return ("yes")
else
return ("no")
break;
case "abonnement":
if (item.abonnement == "304")
return ("premium")
else
return ("none")
break;
default:
return("");
and the adjustments to your grid - add the labelfunction to the following columns
<mx:DataGridColumn headerText="transparence" dataField="transparence" labelFunction="setLabel"/>
<mx:DataGridColumn headerText="abonnement" dataField="abonnement" labelFunction="setLabel" />
I hope we get a distinction credit for this assignment ...
David. -
How to modify Date fields in Canada- ROE
Hi Experts,
I have a requirement to change the Block 10 ( First day worked) and Block 11 (Last day for which paid) logic in the ROE letter in Canada Payroll.
Can anyone please let me know how to customize the ROE fields in Canada payroll.
Thanks in advance,
Saurabhuse CMOD
tcode if u want to change feild Label
can u be some wht little clear -
Jsp waiting for servlet response how to make
Hi All,
i have some doubts about making servlet response for jsp request
Am watched some online reservation sites it search some hotel names untill the hotel names display (between that time)
the image processing shows how can i make like that via jsp and servlet plz expalin with example code plz.
how to make jsp wait to servlet response like that plz reply
ThanksIt's a client side thing. Learn Javascript (and CSS) and if necessary also learn Ajax afterwards. There are nice tutorials at w3schools.com. This issue is not really related to JSP/Servlets.
Displaying the progress image isn't that hard. Just show some <div> element with an image during the onclick. -
Return data from Java servlet in form of JSON encoded parameters in Javascr
How to return data from Java servlet in form of JSON encoded parameters in Javascript handler function call?
The same is implemented in php as the following
echo "sT.handleAjaxResponse(";
echo json_encode($response);
echo ");";
How to do the same in Java servlet?
Thanks.With the rising popularity of JSON (especially with Ajax), support for it has started to appear in the Java community. I am not aware of any standardized approach yet, but expect it is likely we'll see that eventually. For now, you probably want to look at a third-party library such as the [JSON in Java Library|http://www.json.org/java/], Jettison, or [Java Tools for the JSON Format|http://jsontools.berlios.de/].
-
How to modify a servlet response?
Hi all,
I want to modify the servlet response string returned by the portal irj servlet.
For this I created a filter.
Now my requirement is to do something like this in the doFilter method:
doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
PrinterWriter pq = res.getWriter();
Reader reader = new StringReader(printWriter.toString());
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
line.replaceAll("Welcome", "Welcome to XXXX");
What I am trying to do is in the response stream replace the letter welcome with "Welcome to XXXX".
I know I cant accomplish this by the code given above.
Any body has a code snippet of how to get this working?
ThanksHi,
You are already in the right way, things missing are:
1. Forgot the do the filter chain
filterChain.doFilter(request, wrapper);
2. Write back the modified stream to response
// write the response stream
response.setContentLength(responseStr.length());
response.getWriter().write(responseStr);
You can use the HttpServletResponseWrapper to manipulate the response too, check the examples at this link:
http://www.jsp-develop.de/faq/show/47/
Greetings,
Praveen Gudapati
[Points are always welcome for helpful answers] -
Modify Servlet response using filter
This is the code wht i am using, this is an example give in the oronserver.com and some other sites too..
import javax.servlet.*;
public class GenericFilter implements javax.servlet.Filter {
public FilterConfig filterConfig;
public void doFilter(final ServletRequest request,
final ServletResponse response,
FilterChain chain)
throws java.io.IOException, javax.servlet.ServletException {
chain.doFilter(request,response);
public void init(final FilterConfig filterConfig) { this.filterConfig = filterConfig;
public void destroy() {
=============================================================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class FilterServletOutputStream extends ServletOutputStream {
private DataOutputStream stream;
public FilterServletOutputStream(OutputStream output) {
stream = new DataOutputStream(output);
public void write(int b) throws IOException {
stream.write(b);
public void write(byte[] b) throws IOException {
stream.write(b);
public void write(byte[] b, int off, int len) throws IOException {
stream.write(b,off,len);
===================================================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class GenericResponseWrapper extends HttpServletResponseWrapper {
private ByteArrayOutputStream output;
private int contentLength;
private String contentType;
public GenericResponseWrapper(HttpServletResponse response) {
super(response);
output=new ByteArrayOutputStream();
public byte[] getData() {
return output.toByteArray();
public ServletOutputStream getOutputStream() {
return new FilterServletOutputStream(output);
public PrintWriter getWriter() {
return new PrintWriter(getOutputStream(),true);
public void setContentLength(int length) {
this.contentLength = length;
super.setContentLength(length);
public int getContentLength() {
return contentLength;
public void setContentType(String type) {
this.contentType = type;
super.setContentType(type);
public String getContentType() {
return contentType;
===========================================================
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class PrePostFilter extends GenericFilter {
public void doFilter(final ServletRequest request,
final ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
OutputStream out = response.getOutputStream();
out.write("<HR>PRE<HR>".getBytes());
GenericResponseWrapper wrapper = new
GenericResponseWrapper((HttpServletResponse) response);
chain.doFilter(request,wrapper);
out.write(wrapper.getData());
out.write("<HR>POST<HR>".getBytes());
out.close();
===========================================================
filter3.jsp
<HTML>
<HEAD>
<TITLE>Filter Example 3</TITLE>
</HEAD>
<BODY>
This is a testpage. You should see<br>
this text when you invoke filter3.jsp, <br>
as well as the additional material added<br>
by the PrePostFilter.
<br>
</BODY>
</HTML
When i run the above code i am not getting data which is there in the jsp page, i am getting data which i am writing it in the prepostFilter.
the output is
PRE
Post
Is the above is overwriting the actual response ?
If so can anyone tell me how to modify the response of the servlet instead of overwriting.............i will so thankful to you.i run your codes and get the following:
PRE
This is a testpage. You should see
this text when you invoke filter3.jsp,
as well as the additional material added
by the PrePostFilter.
POST
my testing environment is
sun j2ee ri 1.3.1
and i deploy filter3.jsp and set the filter Mapping as the following
Filter Name: PrePostFilter
Target Type: Url Pattern
Target : /* -
How can I know whether the Servlet is sending a response!!!
Hello,
My question is this :
How do I know whether that server outputstream is sending me a response or not?
I have opened the Client InputStream to recieve a response from a servlet,but how
can i be sure that i will receive a response from the servlet?
I cud be waiting for an 15 expecting a response but havent received one..
Is there any way to check whether the servlet is sending me a response?
The reason I am asking is this.
I have written a Java Client that connects to a servlet.It has to wait for a
response from the servlet.It will wait for 5 seconds and if this doesnt recieve
a response,it will return back else it will display the response.
I have set a timer on my client for 5 seconds and a timer on the servlet for 15 seconds.
Essentially,when the client connects,the servlet response is held for 15 seconds
and the client tries for 5 seconds.
But the client is unable to exit without a response.The response comes back in 15 seconds.
The client shud have the message 'Connection Timed Out' after 5 seconds.
This means there is an error somewhere.
As the response takes 15 seconds,the client shudnt recieve one.
So,is there a way I can block the servlet response?
I am using threads and Inner classes for the timer purposes..
Please can any one help me?
ajay
Client code:
public class HttpHandler {
private static String sURL="localhost";
static String sMessage="Hello Server..Client sending Data";
static DataInputStream dis = null;
static HttpURLConnection hpCon=null;
public static void main(String[] args)
sendData(sMessage);
public void TimerTest() {
NewThread nt = new NewThread();
public static void sendData(String sMess)
String response=null;
try{
// Invoke Timer
new HttpHandler.TimerTest();
URL url=null;
String uri = "http://" + sURL + ":8080/servlet/threads.Recieve_Http_Data1";
url = new URL(uri);
hpCon=null;
hpCon = (HttpURLConnection)url.openConnection();
hpCon.setDoOutput(true);
hpCon.setDoInput(true);
// Transfer Data over http
DataOutputStream dos = new DataOutputStream(hpCon.getOutputStream());
dos.writeUTF(sMess);
}catch(IOException e)
{System.out.println("Error in Client " + e); e.printStackTrace();}
} // End of Method sendData
// Inner Class
class NewThread extends Thread
String response;
int i=0;
NewThread()
start();
public void run()
try {
while(i < 5)
System.out.println(i);
Thread.sleep(1000);
try {
dis = new DataInputStream(hpCon.getInputStream());
response = dis.readUTF();
// If response recieved, break off else Loop back.
if(dis !=null)
System.out.println("SERVER RESPONSE : " + response);
dis.close();
break;
}catch(IOException e){System.out.println("Here : " + e);}
i++;
} // End of While.
}catch(InterruptedException e){}
The Servlet
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.io.*;
import java.sql.*;
import java.math.*;
public class Recieve_Http_Data1 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
doPost(request,response);
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
System.out.println("Server Ready to receive Message from application :");
System.out.println();
BufferedReader br=null;
// Data Read by the Servlet
String sMess="";
DataInputStream dis = new DataInputStream(request.getInputStream());
sMess = dis.readUTF();
System.out.println("Received from Client: " + sMess);
// Send response back after 15 seconds Only.
try {
for(int i=0;i<15;i++)
System.out.println(i);
DataOutputStream dos = new DataOutputStream(response.getOutputStream());
String sResponse = "Hello Client...This is server sending response";
dos.writeUTF(sResponse);
Thread.sleep(1000);
}catch(InterruptedException e){}I don't know whether you solve your problem or not! Anyway, I have the same problem. The program hangs when getInputStream is called.
DataInputStream dis = new DataInputStream(request.getInputStream());
If you have the answer, please let me know. Thanks!! -
How to modify user responsibility
Hi,
Please suggest me how to modify the user responsibility in oracle apps 11i.
I have a user, he has system Administration role, however he wants System Administrator. Let me know how to change it.
Thanks,
-vinodPlease suggest me how to modify the user responsibility in oracle apps 11i.
I have a user, he has system Administration role, however he wants System Administrator. Let me know how to change it.You can assign responsibilities from (System Administrator responsibility > Security > User > Define). If you want to end-date the other responsibility/role then you can do from the same screen or from User Management responsibility.
Thanks
Hussein
Maybe you are looking for
-
My son was on a linked apple id now I have created my own how can he retain his downloads from his old account
-
LaserJet 600 M602 very slow between each documents
Hi, Our Laserjet 600 M602 printer is very slow to print between each documents. (around 30 seconds). Same problem with osx 10.6, 10.7, 10.8 and 10.9. Can someone help me?
-
Does the Communications API work with Studio 4
I just installed Studio 4 along with the JDK. The Java version that I am running now is: java version "1.4.1_02" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06) Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode) Running
-
Does anybody know that when phone(n82) is switched on the light is pretty bright but after some time it becomes very low! As well when any incoming call or alarm rings the light is increased and when it is stopped then again it comes to normal. Do an
-
Lost all my iPhone notes during last synch - how do I get them from time machine?
I lost all my iPhone notes in last synch - how do i get them back?