这是JSP文件:提交按钮不起作用
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<html lang="en">
<head>
<title>FIKT | Sign Up</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="CSS/index.css">
<link href="http://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link rel="icon" type="image/x-icon" href="Images/icon.ico">
<script>
$(document).ready(function(){
$("#buttonTeacher").click(function(){
$(".teacher").css("display", "block");
$(".signUp").css("display", "inline");
$(".student").hide();
});
$("#buttonStudent").click(function(){
$(".student").css("display", "block");
$(".signUp").css("display", "inline");
$(".teacher").hide();
});
});
</script>
</head>
<body data-spy="scroll" data-target=".navbar" data-offset="50">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="Login.jsp">FIKT</a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li><a href="About.jsp">ABOUT</a></li>
<li><a href="Login.jsp">SIGN IN</a></li>
<li><a href="Register.jsp">SIGN UP</a></li>
<li><a href="Contact.jsp">CONTACT</a></li>
</ul>
</div>
</div>
</nav>
<div class="container" id="signInDiv">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default text-center">
<div class="panel-heading">
<h1>SIGN UP</h1>
</div>
<div class="panel-body">
<form class="form-horizontal" role="form" action="/Hello_World/RegisterServlet" method="get">
<div class="form-group">
<h4>Please choose:</h4><br>
<div class="panel-footer">
<button class="btn btn-lg" id="buttonTeacher">Teacher</button>
<button class="btn btn-lg" id="buttonStudent">Student</button>
</div>
</div>
<div class="form-group teacher" style="display:none;">
<label class="control-label col-sm-2" for="first">First:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="Enter your first name" required>
</div>
<label class="control-label col-sm-1" for="last">Last:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Enter your last name" required>
</div>
</div>
<div class="form-group teacher" style="display:none;">
<label class="control-label col-sm-2" for="idTeacher">Teacher ID:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="teacherId" name="teacherId" placeholder="Enter your teacher ID" required>
</div>
<label class="control-label col-sm-1" for="pass">Password:</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="password" name="password" placeholder="Enter your password" required>
</div>
</div>
<div class="form-group teacher" style="display:none;">
<label class="control-label col-sm-2" for="email">E-mail:</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email" required>
</div>
</div>
<div class="form-group student" style="display:none;">
<label class="control-label col-sm-2" for="first">First:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="firstName" name="firstName" placeholder="Enter your first name" >
</div>
<label class="control-label col-sm-1" for="last">Last:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="lastName" name="lastName" placeholder="Enter your last name" >
</div>
</div>
<div class="form-group student" style="display:none;">
<label class="control-label col-sm-2" for="idStudent">Student index:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="teacherId" name="studentId" placeholder="Enter your index" >
</div>
<label class="control-label col-sm-1" for="pass">Password:</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="password" name="password" placeholder="Enter your password" >
</div>
</div>
<div class="form-group student" style="display:none;">
<label class="control-label col-sm-2" for="email">E-mail:</label>
<div class="col-sm-9">
<input type="email" class="form-control" id="email" name="email" placeholder="Enter your email" >
</div>
</div>
<div class="panel-footer">
<button class="btn btn-lg signUp" type="submit" style="display:none;">Sign Up</button>
</div>
</form>
</div>
</div>
</div>
</div>
<footer class="container-fluid text-center">
<a href="#myPage" title="To Top">
<span class="glyphicon glyphicon-chevron-up"></span>
</a>
<p>Bootstrap Theme Made By <a href="http://www.kddesign.comlu.com" title="Visit KDdesign">© KDdesign All rights reserved 2016</a></p>
</footer>
</body>
</html>
和Java Servlet的处理它:
package gui;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Helloworld
*/
@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public RegisterServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String teacherId = request.getParameter("teacherId");
String studentId = request.getParameter("studentId");
String firstName = request.getParameter("firstName");
String lastName = request.getParameter("lastName");
String password = request.getParameter("password");
String email = request.getParameter("email");
DbConnector db = new DbConnector();
db.Connect();
System.out.println(firstName+" "+lastName+" "+teacherId);
System.out.println(studentId);
if (firstName !=null && password !=null && !db.validateUser(firstName, password)){
if (teacherId!=null){
System.out.println("teachers");
db.addUser(teacherId, firstName, lastName, password, email,"teacher");
}
else {
System.out.println("studenti");
db.addUser(studentId, firstName, lastName, password, email,"student");
}
request.setAttribute("user", firstName);
request.getRequestDispatcher("Success.jsp").forward(request, response);
}
else
System.out.print("FAILED!");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
当学生的div被选中,点击注册该按钮不运行servlet RegisterServlet.Why我的按钮只为老师div提交而不是两个..?