Java Servlet - Editing an HTML file

I've got a tomcat server running running for a project. The project is writing a servlet that takes a name, uses this name to issue a mysql query to a local database, then displays the results of this query in an html table.

I have an html page set up, I know how the table should be created and all that. The only issue I'm seeing is how am I going to easily insert this data into a pre-existing HTML page? Would I just open up the HTML document, find the <table> tag, and just start inserting rows right after that, then send back the modified file?

Hmm I feel like just writing this out kind of answered my own question :)
Last edited on
You're sending a get request to the server, it's going to figure out what you want, and respond. The typical response is HTML, so the creation of the page is going to be server side. I don't know what you are using to create the html ( do you even have an html file? ).

Another method is to have your server respond with just the data about that person ( typically in JSON format ). I do believe JSON was made for Javascript ( a JSON string can be converted to a Javascript object no prob ). Once you have that object, you use Jquery ( or more javascript ) to set the table's values directly. That would be client side.

The JSON method is faster ( for server side at least, you don't have to create the HTML, and send back much less data in response). However, I bet your server is already set up to dynamically create HTML and respond with that.
Last edited on
I do have an HTML page currently. Statically written. What I want to happen is the make it seem like to the user that the table of results is just inserted into the page. I realize that actually inserting isn't really possible, so should I just recreate the page server side but add in the table populated with results? This way the page returned would be exactly the same as the query page, with the addition of the results.

I'm new to this whole web development stuff so bear with me :)

I can send you the link to the page if you want, so you know kinda what I mean.
If you want to, I'm not sure there is much i can get from viewing just a web page

I think you want to use JSP. Looks like that is the way to embed Java into an html.
http://en.wikipedia.org/wiki/JavaServer_Pages

Try adding the ".jsp" extension to the end of your html and add this:
1
2
3
4
5
<p>Counting to three:</p>
<% for (int i=1; i<4; i++) { %>
    <p>This number is <%= i %>.</p>
<% } %>
<p>OK.</p>


It should be possible to declare a variable within the function that handles the get request and use it within the .html.jsp file.
Last edited on
Hi, Im prorgamming a pdf converter in VB language, in which the pdf to html conversion stucks me, can you gave some help on my APIs and sample codes, Im unsure what's wrong.

http://www.rasteredge.com/how-to/vb-net-imaging/pdf-converting/
http://www.rasteredge.com/how-to/vb-net-imaging/pdf-convert-html/
Topic archived. No new replies allowed.