• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Parameters to Java Bean  RSS feed

 
Nathan Johnson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!
Basically what is required is a .jsp login form which allows users to enter their login and password. These values are then passed to a java bean which then connects the user to a database.
I am dismayed to the point of disillusion that the workings of such a simple concept has eluded me for the past three days!
Any help would be greatly appreciated!
Thanks NJ
 
Junilu Lacar
Sheriff
Posts: 10950
158
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far? There are many examples to be found on the Internet. Download the Java Pet Store Demo and check that out.
Junilu
 
Nathan Johnson
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Junilu,
I am just downloading Pet Store now!
Here is my code so far.
LoginForm.jsp
<html>
<head>
<title>Inventory Login</title>
</head>
<body>
<%jsp:useBean id="invlog" class="DBAccessBean" />
String userid = request.getParameter("userid");
String passwd = request.getParameter("password");

User: <jsp:setProperty name="invlog" property="userID" value=<%=userid> /> <br />
Password: <jsp:setProperty name="invlog" property="password" value="<%=passwd> />

/>
</body>
</html>
DBAccessBean.java
import javax.servlet.http.*;
import javax.servlet.*;
import java.util.*;

public class dbAccessBean {

HttpServletRequest httpRequest = null;
public void setRequest(HttpServletRequest request) {
// Store the request object - temporarily.
httpRequest = request;
// If there is no sessionId nothing else can be done.
if(getSessionId(httpRequest) == null) {
return;
}
}
String getClientId() {
// If request isn't set return null.
if(httpRequest == null) return null;
// Return parameter value.
return httpRequest.getParameter("userid");
}

String getPassword() {
// If request isn't set return null.
if(httpRequest == null) return null;
// Return parameter value.
return httpRequest.getParameter("passwd");
}

//Database connection(?)
java.util.Properties info = new java.util.Properties();
info.put ("user", userid);
info.put ("password", passwd);
info.put ("defaultRowPrefetch","15");
System.out.println("Loading Oracle Driver");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException e) {
System.out.println("Could not load the driver!");
e.printStackTrace();
}
System.out.println("Connecting to the database");
Connection conn = null;
try {
conn = DriverManager.getConnection
("jdbc racle:thin racle:@129.73.78.130:1521 emo", info);
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!