Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INDEX>HTML
- <%@page import="packageForLab7.Dolj"%>
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <script src="http://code.jquery.com/jquery-latest.min.js"></script>
- <title>main menu</title>
- </head>
- <body>
- <center>
- <form action="/lab7/" method="POST">
- <input type="button" name="dolj" value="должности" onclick="btnClick(this)" />
- <input type="button" name="sotr" value="сотрудники" onclick="btnClick(this)" />
- <input type="button" name="rabNaKasse" value="раб на кассе" onclick="btnClick(this)" />
- <input type="button" name="kassa" value="кассы" onclick="btnClick(this)" />
- <input type="button" name="bilet" value="билеты" onclick="btnClick(this)" />
- <input type="button" name="query" value="запрос" onclick="btnClick(this)" />
- <input type="submit" name="exit" value="выход" />
- </form><hr>
- <div class="table"></div>
- </center>
- <script>
- function btnClick(self) {
- $(".table").text('');
- $.ajax('http://localhost:8080/lab7/query.jsp?' + self.getAttribute('name') + '=1', {
- type: 'GET',
- dataType: 'html',
- success: function(msg) {
- $(".table").append(msg);
- console.log(msg);
- }
- });
- }
- </script>
- </body>
- </html>
- QUERY.JSP
- <%@page import="packageForLab7.AllTogether"%>
- <%@page import="packageForLab7.Bilet"%>
- <%@page import="packageForLab7.Kassa"%>
- <%@page import="packageForLab7.RabNaKasse"%>
- <%@page import="packageForLab7.Sotr"%>
- <%@page import="packageForLab7.Dolj"%>
- <%@ page language="java" contentType="text/html; charset=UTF-8"
- pageEncoding="UTF-8"%>
- <%
- try {
- if (request.getParameter("dolj") != null) {
- out.write(Dolj.getTable());
- } else if (request.getParameter("sotr") != null) {
- out.write(Sotr.getTable());
- } else if (request.getParameter("rabNaKasse") != null) {
- out.write(RabNaKasse.getTable());
- } else if (request.getParameter("kassa") != null) {
- out.write(Kassa.getTable());
- } else if (request.getParameter("bilet") != null) {
- out.write(Bilet.getTable());
- } else if (request.getParameter("query") != null) {
- out.write(AllTogether.getTable());
- }
- } catch(Exception err) {}
- %>
- BILET.JAVA
- package packageForLab7;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class Bilet {
- public static String getTable() throws SQLException {
- try {
- String table = "<table border=1><tr><th>код</th><th>фио пассаж</th>"
- + "<th>код раб на кассе</th><th>поезд</th>"
- + "<th>номер вагона</th><th>Номер места</th></tr>";
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/railwaystation", "user", "password");
- PreparedStatement ps = con.prepareStatement("SELECT * FROM билет");
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- table += "<tr><td>" + rs.getString("id") +
- "</td><td>" + rs.getString("fio_pass") +
- "</td><td>" + rs.getString("kod_rab_na_kasse") +
- "</td><td>" + rs.getString("poezd") +
- "</td><td>" + rs.getString("nom_vagona") +
- "</td><td>" + rs.getString("nom_mesta") +"</td></tr>";
- }
- table += "</table>";
- return table;
- } catch (ClassNotFoundException | SQLException e) {
- System.err.println(e.getMessage());
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment