• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

JSP Parameters to Java Bean

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 17008
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic