Hello Sir,
I have a simple Issue but It is not resolve by me i.e input parameter
are not store in Ms-Access.
I store the input parameter through Standard Action <jsp:useBean>.
jsp:useBean call a property IssueData. this property exist in
SimpleBean which create a connection from DB and insert the data.
At run time servlet and server also show that loggging are saved in DB.
But when I open the table in Access. Its empty.
Ms-Access have two fields- User, Password both are text type.
Please review these code:
login.html:
<html>
<head>
<title>A simple JSP application</title>
<head>
<body>
<form method="get" action="tmp" >
Name: <input type="text" name="user">
Password: <input type="password" name="pass">
<input type="Submit" value="Submit">
</form>
</body>
</html>
LoginServlet.java:
import javax.servlet.*;
import javax.servlet.http.*;
public class LoginServlet extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException{
try
{
String user=request.getParameter("user");
String pass=request.getParameter("pass");
co.SimpleBean st = new co.SimpleBean();
st.setUserName(user);
st.setPassword(pass);
request.setAttribute("user",st);
request.setAttribute("pass",st);
RequestDispatcher dispatcher1 =request.getRequestDispatcher("submit.jsp");
dispatcher1.forward(request,response);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
SimpleBean.java:
package co;
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.util.*;
public class SimpleBean {
private String user="";
private String pass="";
private String s="";
public String getUserName() {
return user;
}
public void setUserName(String user) {
this.user = user;
}
public String getPassword() {
return pass;
}
public void setPassword(String pass) {
this.pass = pass;
}
public String getIssueData() //method that create connection with database
{
try
{
System.out.println("Printed*************************************************************");
getUserName();
getPassword();
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
System.out.println("Loading....");
Connection con=DriverManager.getConnection("jdbc:odbc:simple");
System.out.println("Connected....");
PreparedStatement st=con.prepareStatement("insert into Table1 values(?,?)");
System.out.println("~~~~~~~~~~~~~~~~~~~~");
String User=getUserName();
st.setString(1,User);
String Password=getPassword();
st.setString(2,Password);
st.executeUpdate();
System.out.println("Query Executed");
con.close();
s= "Your logging is saved in DB ";
System.out.println("Your logging is saved in DB *****************");
return(s);
}
catch(Exception e)
{
e.printStackTrace();
return "failed";
}
}
}
submit.jsp:
This is Submit page
<html><body>
Hello
Student Name: <%= ((co.SimpleBean)request.getAttribute("user")).getUserName() %>
<br>
Password: <%= ((co.SimpleBean)request.getAttribute("pass")).getPassword() %>
<br>
<jsp:useBean id="st" class="co.SimpleBean" scope="request" />
<jsp:getProperty name="st" property="IssueData" />
</body></html>
web.xml:
<web-app>
<servlet>
<servlet-name>one</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>one</servlet-name>
<url-pattern>/tmp</url-pattern>
</servlet-mapping>
<jsp-file>issue.jsp</jsp-file>
<jsp-file>submit.jsp</jsp-file>
<url-pattern>*.do</url-pattern>
<welcome-file-list>
<welcome-file>Login.html</welcome-file>
</welcome-file-list>
</web-app>
Please Help me..Thanks.!!!