karthick Soundararaj

Greenhorn
+ Follow
since Mar 09, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by karthick Soundararaj

Hi.
I did some googling but i am not able to figure what pattern matching algorithm is being used in Java. Anyone has any idea about the pattern matching algorithm being used?
14 years ago
Take for example google.com

In the text field we enter some words.. then we click on search and we get to see the results..

Now I want to do this automatically through my Java program. Like i want to simulate this process and get the result into some input stream How to do this? Please do reply soon...
14 years ago

hareendran dileep wrote:Karthick,

Whenever you do a response.setHeader, you are sending some instruction to the browser (which initiated the request). In this case with "Content-Disposition" you are advising the browser how to handle the content being streamed to it.

Ulf Dittmer's code says that the browser should treat the response body as an attachment and that it's name to be shown in the File Download dialog is "myFooBar.jar"

Hope this helps!



Thank you.. Now , how do you find these kind of values and header names.. Yes, googling can give us 100's of pages. But still, how does someone himself find the header needed for a particular action?
15 years ago

Kathleen Tillman wrote:I may sound like a dunce, but I'm not quite sure what you mean by "in class not in method main".
Does that mean I need to move it farther down or farther up? And wouldn't that screw up showing the total after the information has been entered? I'm really new to Java, so this may sound like a really dumb question, but I'm confused.
Thanks.



Last line of your code is out of the main method...
15 years ago

Ulf Dittmer wrote:The servlet should set the Content-Disposition header; something like this should do the trick:

response.setHeader("Content-Disposition", "attachment; filename=\"myFooBar.jar\"");




What does this code do? I mean why this value attachment; filename=\"myFooBar.jar\"?

I would like to know what exactly is happening when this value is entered. How does it affect and what does it do?
15 years ago
Hi all.. I have been tryinhg to learn JSP and i got struck up the two tags that i dont understand





So what exactly is the advantage of url rewriting? I know its for sessions? but what exactly is the advantage of session...



Consider the following scenario:
Say i have 2 input fields inputA and inputB....
I use a session...
I enter the 2 values and close the browser..


When i again enter the same url will i get the page with the previously entered values? Is this the purpose of sessions?


My second question is What exactly is the purpose of target attribute of set custom tag?





15 years ago
JSP

steve claflin wrote:The offset is the position to start WRITING in the destination array, not the location to read from in the source stream. The read starts at the current position in the input stream, which is whatever location you left off at from the previous read.



Thanks a lot.. Opened my eye.. i realise how closed thinking i have been having!!

15 years ago
check the log file to see if some exception has occured

15 years ago

Vinoth Thirunavukarasu wrote:Its so simple
The only thing is we have to set context path in your Tomcat/conf/server.xml


<Context path=""
docBase="/SimpleWebApps"
reloadable="true" >
</Context>





where exactly should this be added? i added it in server.xml but it doesnt work.. I get the default page instead..
15 years ago

William Brogden wrote:It has been a while but as I recall, you also need to set the content length header or the browser never decides that it has all the content. You can of course get the file length before you start if you open /graphs.pdf by means of a File instead of getting as stream.

Bill



Thanks bill.. but i have already found the problem... Would be glad if you can answer to my previous post in this thread...
15 years ago

Ulf Dittmer wrote:
Any exceptions in the log files?
You probably meant to say "is.read(bytes)" instead of "is.read()".



Your are rite.. thank you../.


The java documentation says:

The read(b) method for class InputStream has the same effect as:
read(b, 0, b.length)

while the doc for public int read(byte[] b, int off, int len) throws IOException says

It Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to read as many as len bytes, but a smaller number may be read, possibly zero. The number of bytes actually read is returned as an integer.
This method blocks until input data is available, end of file is detected, or an exception is thrown.

If b is null, a NullPointerException is thrown.

If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown.

If len is zero, then no bytes are read and 0 is returned; otherwise, there is an attempt to read at least one byte. If no byte is available because the stream is at end of file, the value -1 is returned; otherwise, at least one byte is read and stored into b.

The first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len. Let k be the number of bytes actually read; these bytes will be stored in elements b[off] through b[off+k-1], leaving elements b[off+k] through b[off+len-1] unaffected.

In every case, elements b[0] through b[off] and elements b[off+len] through b[b.length-1] are unaffected.

If the first byte cannot be read for any reason other than end of file, then an IOException is thrown. In particular, an IOException is thrown if the input stream has been closed.

The read(b, off, len) method for class InputStream simply calls the method read() repeatedly. If the first such call results in an IOException, that exception is returned from the call to the read(b, off, len) method. If any subsequent call to read() results in a IOException, the exception is caught and treated as if it were end of file; the bytes read up to that point are stored into b and the number of bytes read before the exception occurred is returned. Subclasses are encouraged to provide a more efficient implementation of this method.

Parameters:
b - the buffer into which the data is read.
off - the start offset in array b at which the data is written.
len - the maximum number of bytes to read.



My question is if the offset value is set to be 0, then wont the document be read everytime from the beginning when it is put in a loop???

[Edit: large red text will just tick people off. Rule of thumb: don't tick off people you are trying to get to help you.]
15 years ago
I get a black screen in the browser and no download happens,,,,
15 years ago
Hi all, The following code does not work for me.. please do suggest a solution

DownloadPersonalCalc.java

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

public class DownloadPersonalCalc extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException,ServletException
{
res.setContentType("application/pdf");


InputStream is=getServletContext().getResourceAsStream("/graphs.pdf");

OutputStream os=res.getOutputStream();

int read=0;
byte[] bytes=new byte[1024];


while((read=is.read())!=-1)
{
os.write(bytes,0,read);
}
os.flush();
os.close();
}
}

Locations

graphs.pdf: F:\Tomcat\webapps\Calculator\graphs.pdf
DownloadPersonalCalc.java: F:\Tomcat\webapps\Calculator\WEB-INF\classes
15 years ago
Why not a send redirect to a servlet which in turn redirects to another servlet? that way there are two continous redirects although 2 servlets are involved here
15 years ago

Mohamed Inayath wrote:Good.

But your earlier attachment wrt the calci.java says a package definition : classes.

This time I believe you have removed that.



Thing is the statement package classes.Calci itself is wrong statements.. please do look at my location i have mentioned in one of my earlier posts..

Anyways your input regarding the Capital letter was helpful
15 years ago