Click to See Complete Forum and Search --> : Problems with viewing Java output on a webpage


pepper
06-18-2005, 09:34 PM
I have created a small web app that takes in a persons name and address and sorts the data. After all data has been entered into the database(in my case its a vector) the user has the option of specifing the sort they want based on ascending order or descending order and by first or last name. If the user doesn't want to specify sorting options he or she can use the default sort.

Here is my problem. I don't know the Java code to output the html code to a webpage rather then the console. This is what I am doing now. By the way I am using apache struts and Apache Velocity in my web app. I am not using JSP coding.

from my Action class I created a sorted array of my vector. I then create the Context for the output of my web page. In this method I put the contents of what is to be outputed into a StringWriter variable and then return that variable to the Action class. Once I return to the Action class I do the following:

try
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(writer.toString());
}catch(IOException e)
{e.printStackTrace();}

return mapping.findForward("default");

I know I must be doing something wrong, I just can't find it. Please if someone knows anything about writing code to a web page please give me an example.

Thanks

-Pepper