<%--
Document : studentRegistration
Created on : 06-Feb-2012, 20:49:08
Author : eeua9b
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<h1><table border="1">
<tr><td>First name:</td><td><input type="text" name="firstname" /></td></tr>
<tr><td>Last name: </td><td><input type="text" name="lastname" /></td></tr>
<tr><td>Student ID:</td><td><input type="text" id="studentid" /></td></tr>
<tr><td>E-mail: </td><td><input type="text" name="email" /></td></tr>
</table>
<P><INPUT TYPE="SUBMIT" VALUE="Submit" NAME="B1"></P>
</h1>
</body>
</html>
help with web application & mysql
Page 1 of 12 Replies - 805 Views - Last Post: 07 February 2012 - 05:36 PM
Topic Sponsor:
#1
help with web application & mysql
Posted 07 February 2012 - 04:34 PM
hello. i have created a table in HTML with a submit button... how do i submit details of a student registration i.e. the table below to a MySQL database.
Replies To: help with web application & mysql
#2
Re: help with web application & mysql
Posted 07 February 2012 - 05:20 PM
You need a form tag in there too and to write a servlet or jsp that does the jdbc on form submit
#3
Re: help with web application & mysql
Posted 07 February 2012 - 05:36 PM
*Moved to JavaEE forums*
bhavin5: There's quite a bit of work needed to setup a web application. Have you looked at any of the JavaEE tutorials? Check out the J2EE 1.4 tutorial for JSP technology (ch. 13). I'd highly suggest looking on YouTube for the most detailed tutorials you can get.
In regards to the code you posted, as g00se mentioned you need form tags around your input fields and submit button. You must also give a value to the action attribute of the form tag, pointing to a servlet, HTML, or JSP page.
A word of advice: have that action attribute point to some kind of servlet, or another JSP at the very least, that then accesses your database through JDBC, or whatever your using. Putting a whole bunch of programming logic code in JSP pages is bad design and completely unmaintainable. You'll introduce conditional coupling into your design, which is incredibly bad, and you'll have a bunch of mixed HTML and Java. E.g.
With a more modular approach you get something like this:
Now, if I need to concentrate on making UI changes I don't have to work beside a bunch of programming logic. You could let a web developer deal with it! If I need to work on web-tier stuff I get a servlet that's almost pure Java.
bhavin5: There's quite a bit of work needed to setup a web application. Have you looked at any of the JavaEE tutorials? Check out the J2EE 1.4 tutorial for JSP technology (ch. 13). I'd highly suggest looking on YouTube for the most detailed tutorials you can get.
In regards to the code you posted, as g00se mentioned you need form tags around your input fields and submit button. You must also give a value to the action attribute of the form tag, pointing to a servlet, HTML, or JSP page.
A word of advice: have that action attribute point to some kind of servlet, or another JSP at the very least, that then accesses your database through JDBC, or whatever your using. Putting a whole bunch of programming logic code in JSP pages is bad design and completely unmaintainable. You'll introduce conditional coupling into your design, which is incredibly bad, and you'll have a bunch of mixed HTML and Java. E.g.
<html>
<?
if(request.getParameter("username") != null && session.getParameter("logged").equals("false")) { //process form
if(authenticate(username, password) == SUCCESS) {
//open dashboard
<div>
.
.
.
.
</div>
}else {
//show error
}
}else if(session.getParameter("logged").equals(true)) {
//logged in already; redirect to dashboard
}else {
//first visit; show login form
<form>
.
.
.
.
</form>
}
?>
</html>
With a more modular approach you get something like this:
<!-- login.jsp -->
<html>
<form action="/mywebapp/login">
Username: <input type="text" name="username"/>
<input type="submit" value="Login" />
</form>
</html>
//Login Servlet
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
String username = req.getParameter("username");
if(authenticate(username)) {
//login successful, show dashboard
request.getRequestDispatcher().forward("dashboard.jsp");
}else {
//login failed, show login form, and failure message
request.getRequestDispatcher("login.jsp").include(req, resp);
resp.getWriter().write("<br/>Login failed.");
}
}
private boolean authenticate(String user) {
return JdbcUtils.authenticate(user);
}
}
Now, if I need to concentrate on making UI changes I don't have to work beside a bunch of programming logic. You could let a web developer deal with it! If I need to work on web-tier stuff I get a servlet that's almost pure Java.
This post has been edited by blackcompe: 07 February 2012 - 06:46 PM
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote



|