显示不会重定向页面的空白页面&不使用jsp存储在数据库中

时间:2017-09-20 06:18:20

标签: jsp

这是我的JSP代码。当我单击“保存”按钮时,它会显示一个空白页面,并且不会在数据库中存储任何内容。

pdes.jsp

   <jsp:include page="menu.jsp"></jsp:include>
     <%@page import="java.sql.*"%>
    <html>
    <head>
     <style>
         @import "compass/css3";

    @import "compass/css3";
     @import url(https://fonts.googleapis.com/css?
   family=Patua+One|Open+Sans);

    * { 
     -moz-box-sizing: border-box; 
      -webkit-box-sizing: border-box; 
    box-sizing: border-box; 
    }
      html, body {margin: 0; height: 100%; overflow: hidden}
      body {
    background:#353a40;
 }

   table {
   border-collapse: separate;
    background:#fff;
       @include border-radius(5px);
      margin:20px auto;
     @include box-shadow(0px 0px 5px rgba(0,0,0,0.3));
     }

            thead {
   @include border-radius(5px);
 }

  thead th {
     font-family: 'Patua One', cursive;
font-size:16px;
font-weight:400;
color:#fff;
@include text-shadow(1px 1px 0px rgba(0,0,0,0.5));
text-align:left;
  padding:20px;
 @include background-image(linear-gradient(#646f7f, #4a5564));
 border-top:1px solid #858d99;

 &:first-child {
 @include border-top-left-radius(5px); 
}

&:last-child {
  @include border-top-right-radius(5px); 
}
}

tbody tr td {
font-family: 'Open Sans', sans-serif;
font-weight:400;
color:#5f6062;
font-size:13px;
 padding:10px 10px 10px 10px;
 border-bottom:1px solid #e0e0e0;

 }

 tbody tr:nth-child(2n) {
  background:#f0f3f5;
 }

  tbody tr:last-child td {
    border-bottom:none;
 &:first-child {
    @include border-bottom-left-radius(5px);
 }
&:last-child {
  @include border-bottom-right-radius(5px);
}
 }

  tbody:hover > tr td {
  @include opacity(0.5);


 /* color:transparent;
  @include text-shadow(0px 0px 2px rgba(0,0,0,0.8));*/
 }

tbody:hover > tr:hover td {
      @include text-shadow(none);
    color:#2d2d2d;
  @include opacity(1.0);
  }

            .right {
text-align: right;
float: right;
   }input:focus {
   background-color: yellow;
   }
  body{

 color: #000;
  font: 100%/30px 'Helvetica Neue', helvetica, arial, sans-serif;
  text-shadow: 0 1px 0 #fff;
 }

        </style>    
    </head>
    <body>   <form method="POST" action="pdesad.jsp">
        <table><tr><td bgcolor='#c5eee7'>
                    <table  style="float:left;">
                         <%
              Connection conn = null;
  String url = "jdbc:mysql://localhost:3306/";
    String dbName = "login";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root";
  String password = "";

  Statement st;
               try {
    Class.forName(driver).newInstance();
    conn = DriverManager.getConnection(url + dbName, userName, password);

    String query1 = "select * from pdept";
    st = conn.createStatement();
    ResultSet rs = st.executeQuery(query1);
    %>

            <tr><th colspan="2"> <h1><center>Designation Details</h1></th>
  </tr>



            <tr><td>Department:</td><td> <select name="dept">
    <%
    while(rs.next())
    {
        %>
        <option><%=rs.getString(2)%></option>
        <%
    }

               }
               catch(Exception e)
               {
                   out.print(e);
               }
            %>
    </select></td></tr>
                   <tr><td>Designation:</td><td><input name="des" 
 type="text" required="required" ></td></tr>

        <tr><td> <input type="submit" value="Save"></td><td> <a 
class="right" href="Second" style="color: red;text-
decoration:none;">Close</a></td></tr><br>

        </table></td>

    </body>
  </html>
  <br>
<%

try {
    Class.forName(driver).newInstance();
    conn = DriverManager.getConnection(url + dbName, userName, password);

    String query = "select * from pdes";
    st = conn.createStatement();
    ResultSet rs = st.executeQuery(query);
    %>
    <td style="vertical-align:top;"> <div id="kryesore" style="overflow-y: 
scroll;height:250px;">
       <table border="1" style="float:right;" width="400">
           <tr><th bgcolor='#C0C0C0' colspan="3">Employee Designation 
Master</th></tr>
           <tr><th>Department</th><th>Designation</th>
</tr>
<%
    while (rs.next()) {
%>

  <tr><td><%=rs.getString("dept")%></td><td><%=rs.getString("des")%></td>
<td><a style="color:#ff00cc;text-decoration:none;" href="pdesedit.jsp?id=
 <%=rs.getString("id")%>">Edit</a></td><td><a style="color:#ff00cc;text-
decoration:none;" href="pdesdel.jsp?id=<%=rs.getString("id")%>">Delete</a>
</td></tr>

<%
    }
 %>
       </table></div></td></tr></table>   </form>
<%
}
    catch(Exception e)
            {
            out.println(e);
            }
 %> 

pdesad.jsp

 <%@page import="java.sql.*,java.util.*"%>
 <%
 String dept=request.getParameter("dept");
String des=request.getParameter("des");

      try{
     Class.forName("com.mysql.jdbc.Driver");
       Connection con = 
 DriverManager.getConnection("jdbc:mysql://localhost:3306/login", "root", 
"");
       Statement st=con.createStatement();
       int i=st.executeUpdate("insert into pdes(dept,des) 
    values('"+dept+"','"+des+"')");
    response.sendRedirect("pdes.jsp");
    }
    catch(Exception e){
    System.out.print(e);
    e.printStackTrace();
    }
    %>

Java控制台在尝试加载CSS时显示404。它不会转到catch子句。

0 个答案:

没有答案