基本形式portlet jsr 286 v liferay 6.0
如何从表单中检索数据并通过JDBC将其发送到MySQL数据库?基本形式portlet jsr 286 v liferay 6.0
这里是我的方法:
主类:
public class Dati extends MVCPortlet { public static Connection con() {
Connection conn = null;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (Exception ex) {
System.out.println("Errore");
}
// APRI CONNESSIONE
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/db_alex","root","25071984");
System.out.println("Connessione effettuata");
return conn;
} catch (SQLException ex) {
System.out.println("SQlException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
return null;
}
}
public void Invio (ActionRequest actionRequest, ActionResponse actionResponse)
throws PortletException, IOException {
String username = actionRequest.getParameter("username");
String password = actionRequest.getParameter("password");
Connection conn = null;
try {
Statement st = conn.createStatement();
st.executeUpdate("INSERT INTO contacts (username,password) values ('"+username+"','"+password+"')");
System.out.println("Inserimento avvenuto con successo");
} catch (Exception e) {
System.out.println("Inserimento non avvenuto");
}
}
}
view.jsp的
<% /**
* Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<portlet:actionURL name="Invio" var="Invio"/>
<form method="post" action="actionURL/>">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Invia!">
</form>
我不知道我的错是。我正在阅读Portlet is temporarily unavailable并应用该规则,但是Liferay说我错了。
哪个是正确的存储过程?
回答:
您将actionURL Invio定义为view.jsp中的java对象,但您引用它错误。 您应该在<%=%>标记中引用它。其实你的表单标签应该是这样的:
<form method="post" action='<%=Invio%>'> <input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Invia!">
回答:
请检查表单标签的action属性的值。
您可以在很多方面使用。
1. <form method="post" action="<portlet:actionURL/>"> <input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Invia!">
</form>
2.
<form method="post" action="${Invio}"> <input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Invia!">
</form>
<form method="post" action="<%=Invio%>"> <input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Invia!">
</form>
第三个我不喜欢。
选择是你的....
以上是 基本形式portlet jsr 286 v liferay 6.0 的全部内容, 来源链接: utcz.com/qa/258633.html