Vote count:
0
I want to be able to click on an HTML button and have it call a method inside of Java. Is there more than one way to accomplish this task.
I also would like to see where the errors are coming from on this example. It will not compile.
Java Code:
import java.io.IOException;
@WebServlet("/myservlet")
public class MyServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
MyClass myClass = new MyClass();
if (request.getParameter("button1") != null) {
myClass.function1();
} else if (request.getParameter("button2") != null) {
myClass.function2();
} else if (request.getParameter("button3") != null) {
myClass.function3();
}
request.getRequestDispatcher("/WEB-INF/some-result.jsp").forward(request, response);
}
}
class MyClass {
void function1() {
System.out.println("Button 1");
}
void function2() {
System.out.println("Button 2");
}
void function3() {
System.out.println("Button 3");
}
}
html code:
<html>
<head>
<title>Test Button</title>
</head>
<body>
<form action="${pageContext.request.contextPath}/myservlet" method="post">
<input type="submit" name="button1" value="Button 1" />
<input type="submit" name="button2" value="Button 2" />
<input type="submit" name="button3" value="Button 3" />
</form>
</body>
</html>
Error:
May 30, 2014 1:16:54 PM com.microsoft.sqlserver.jdbc.SQLServerConnection <init>
SEVERE: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
Exception in thread "main" java.lang.UnsupportedOperationException: Java Runtime Environment (JRE) version 1.7 is not supported by this driver. Use the sqljdbc4.jar class library, which provides support for JDBC 4.0.
at com.microsoft.sqlserver.jdbc.SQLServerConnection.<init>(SQLServerConnection.java:304)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1011)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:215)
at testpak.DbTest.testQuery(DbTest.java:19)
at testpak.DbTest.main(DbTest.java:30)
asked 22 secs ago
Aucun commentaire:
Enregistrer un commentaire