我在将字符串返回到JSP页面上的组件时遇到了一些麻烦。我已经构建了一个非常简单的页面如下:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<div id="logindiv" class="centered">
<h1>DB Schema status</h1>
<form action="DBConnectionTester" method="post">
<input type="text" name="usr" placeholder="DB Username" style="text-align: center;">
<br>
<input type="password" name="pwd" placeholder="DB Password" style="text-align: center;">
<br>
<input type="submit" value="Get Schema" class="btn btn-default btn-xs">
<br>
<br>
<c:if test="${not empty rtnmsg}">
<h6>${message}</h6>
</c:if>
</form>
</div>
背后的课程如下:
@WebServlet("/DBConnectionTester")
public class DBConnectionTester extends HttpServlet {
String rtnmsg = "";
DBConnection dbcon = new DBConnection();
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
dbcon.usr = request.getParameter("usr");
dbcon.pwd = request.getParameter("pwd");
dbcon.sampletest();
rtnmsg = dbcon.rtnstr;
}
}
为了澄清,DBConnection如下:
public class DBConnection {
public String usr;
public String pwd;
private static String mySQLCon = "jdbc:mysql://<REDACTED>zeroDateTimeBehavior=convertToNull";
public String err;
public String stmt;
public String rtnstr;
void sampletest()
{
try
{
Connection mCon = DriverManager.getConnection(mySQLCon, usr, pwd);
mCon.getSchema();
err = "No connection issues";
}
catch (SQLException e)
{
err = e.toString();
}
Date date = new Date();
rtnstr = err + date.toString();
}
}
现在,每当我点击提交按钮时,我的浏览器似乎都会访问该类本身 - 也就是说,浏览器中的URL如下所示:http://<REDACTED>elasticbeanstalk.com/DBConnectionTester
我在这里缺少什么?