Skip to content Skip to sidebar Skip to footer

Jsp Java Code + Html Table

I have encountered a problem that I don't really understand. I'm using java code to access a database and then using the jsp part, display in html format the result. The code looks

Solution 1:

If you get a blank page, then this is often caused because an exception is been thrown in midst of rendering the response and the servletcontainer is unable to display the standard error page with exception details, because the response is already committed.

The exception will be logged to server log file. Lookup it, read the stacktrace and fix the problem accordingly.


Unrelated to the actual problem, the code practice you're showing is actually a poor practice. Java code should go in a Java class (controlled by a servlet) and HTML code should go in JSP without utilizing out.println(). JSTL should be used to control the page flow. See also this answer for an example. This way exceptions will/can be caught timely and end up in an error page.

Solution 2:

First of all this is not how you should use jsp. On jsp use jstl on servlet use java code.

and about your issue try checking generated HTML. It should have

<form ...>
.
.
.
.<inputtype="submit" name="something" value="delete"/>
.<inputtype="submit" name="something" value="update"/>
</form>

Or check for server's log,

See also

Solution 3:

Surround your :

ResultSet rs = s.executeQuery("select * from Products");
while(rs.next()){
out.println("<tr><td>" + rs.getString(2) + "</td><td>" + rs.getString(3) + "</td><td>" + rs.getString(4) + "</td><td><inputtype=\"submit\" value=\"Delete\" name=\"delete" + rs.getString(1) + "\"/></td><td><inputtype=\"submit\" value=\"Update\" name=\"update" + rs.getString(1) + "\"/></td></tr>");
   } 

with a try/catch block to see if there is an Exception.

Solution 4:

Don't use connection process and other updating process in jsp page, try to use servlets or other javabeans. tag to use that servlets... if u want to update means simply cal that function, declared inside that servlet. servlet s act as a controller of ur jsp page.its more powerful.

Solution 5:

Why dont you put the variables in request

request.setAttribute("string1",rs.getString(1));

then call it in your jsp

<td><%=request.getParameter("string1")%>;

Post a Comment for "Jsp Java Code + Html Table"