我在eclipse.i中编写了一个简单的servlet程序,创建了一个数据库名称ideationportal并尝试从该数据库中获取数据。但是servlet返回空白页面。请帮助我摆脱这个问题。
我的jsp包含以下表单代码
<form action="Login" method="post">
<p>User ID <br><input type="text" id="username" name="uname" placeholder="username" size="52" ><br/> <br/>
Password<br><input type="password" id="password" name="pwd" placeholder="password" size="52"><br/><br/></p>
<input type="submit" value="Login" size="40"><br/>
</form>
我的servlet包含以下代码
package com.control;
import java.sql.*;
import java.io.IOException;
import java.io.PrintWriter;
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 Login
*/
@WebServlet("/Login")
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Login() {
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
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out=response.getWriter();
response.setContentType("text/html");
String uname=request.getParameter("uname");
String pwd=request.getParameter("pwd");
try {
Class.forName("com.mysql.jdbc.driver");
Connection connection=DriverManager.getConnection("jdbc:mysql://localhost:3306/ideationportal","root","");
Statement statement=connection.createStatement();
String selectsql="SELECT first_name,last_name FROM master_employee_table";
ResultSet rs=statement.executeQuery(selectsql);
while(rs.next())
{
if(uname.equals(rs.getString("username")) && pwd.equals(rs.getString("pass")))
{
out.println(rs.getString("first_name")+"");
out.println(rs.getString("last_name"));
}
else
{
out.println("failed");
}
}
} catch (SQLException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}