我从数据库中检索了信息,但是如何正确格式化?也许使用html

时间:2016-01-05 15:04:08

标签: servlets html-table resultset

我已经通过servlet从数据库中检索了信息,并且我能够使用相同的servlet(在使用tomcat的网页上)打印它。但为了很好地格式化它(可能像一个表),我可能不得不使用html。有人可以帮我解决这个问题吗?也许将值传递给html页面并显示它?谢谢:))

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class PersonalInfoOutput extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();

            String firstname = request.getParameter("firstname");
            String lastname = request.getParameter("lastname");
            String address = request.getParameter("address");
            boolean st = false;
            try { 
                Class.forName("com.mysql.jdbc.Driver").newInstance(); 
                Connection con =    DriverManager.getConnection("jdbc:mysql://localhost:3306/payroll_system", "root", ""); 
                PreparedStatement ps = con.prepareStatement("select FirstName, LastName, Address from payroll_system.employee_info where employeeID = 1234"); 
                ResultSet rs = ps.executeQuery(); 
                st = rs.next(); 
                if(st){

                out.println(rs.getString("FirstName"));
                out.println(rs.getString("LastName"));
                out.println(rs.getString("Address"));

                }
             }catch(Exception e)
              {
                  e.printStackTrace();
              }
            out.close();
    }
}

0 个答案:

没有答案