为什么在JSP中给出HTTP Status 500 – Internal Server Error?

时间:2019-06-17 06:49:59

标签: java jsp servlets

我试图将整数值插入数据库,但这一次又一次地给我错误。我在任何地方做错了还是有解决方案? enter image description here 代码:

<form action="" method="post">
                    <div class="form-group">
                        <label for="product_name">Product Name</label>
                        <input type="text" class="form-control" id="product_name" name="product_name" placeholder="Product Name">
                    </div>
                    <div class="form-group">
                        <label for="product_price">Product Price</label>
                        <input type="number" class="form-control" id="product_price" name="product_price" placeholder="Product Price">
                    </div>
                    <button type="submit" class="btn btn-primary">Submit</button>
                </form>
            </div>
        </div>
<%@ include file="footer.jsp" %>    
</html>
<%
String product_name=request.getParameter("product_name");
int product_price =Integer.parseInt(request.getParameter("product_price"));
String url="jdbc:mysql://localhost:3306/shopbilling";
Connection conn=null;
PreparedStatement ps=null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
if(product_name !=null){
    try{
        conn=DriverManager.getConnection(url,"root","");
        String query="Insert into products_tbl(product_name,product_price) values(?,?)";
        ps=conn.prepareStatement(query);
        ps.setString(1,product_name);
        ps.setInt(2,product_price);
        ps.executeUpdate();
        response.sendRedirect("products.jsp");
    }catch(Exception ex){
        out.println("Your Connection Failed");
    }
}
%>

0 个答案:

没有答案