i have a jsp file which gets some details from the user like name and surname. I want to save the user's answers and use them in a java class to save them in a database. Does anyone knows how can this happen?
Thanks Al
i have a jsp file which gets some details from the user like name and surname. I want to save the user's answers and use them in a java class to save them in a database. Does anyone knows how can this happen?
Thanks Al
Yes - submit them with a form. Then you can read them with request.getParameter(..)
. Then use JDBC to store them in a database.
The basic way of doing this is to import the class you'll be using, instantiate that class, and then pass the form variables to it using that class's methods.
Here's a quick example:
<%@page import="MyClass" %>
<%
MyClass myClassInstance = new MyClass();
//get the value of the submitted form element called "name"
String nameString = request.getParameter("name");
if(nameString != null && nameString.length() > 0)
myClassInstance.setName(nameString);
%>
//the rest of the JSP would follow
As you say, you already know how to use JDBC, so it should be trivial to get that value into a database once it's in the Java class.