基本表单portlet jsr 286 v liferay 6.0

基本表单portlet jsr 286 v liferay 6.0,liferay,portlet,jsr286,Liferay,Portlet,Jsr286,如何从表单中检索数据并通过JDBC将其发送到MySQL数据库 以下是我的程序: 主要类别: public class Dati extends MVCPortlet { public static Connection con() { Connection conn = null; try { Class.forName("com.mysql.jdbc.Driver").newInstance(); } catch

如何从表单中检索数据并通过JDBC将其发送到MySQL数据库

以下是我的程序:

主要类别:

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> 

我不知道我的错在哪里。我在阅读并应用这条规则,但Liferay说我错了


哪个是正确的存储过程?

您在view.jsp中将actionURL Invio定义为java对象,但引用错误。 您应该在标记中引用它。实际上,您的表单标签应该如下所示:

<form method="post" action='<%=Invio%>'>

<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Invia!">    


请检查表单标记的操作属性值

你可以用很多方法

1.  <form method="post" action="<portlet:actionURL/>">
       <input type="text" name="username">
       <input type="password" name="password">
       <input type="submit" value="Invia!">    
   </form> 
1。
2.


3.


第三个我不喜欢


您可以选择……

u可以使用service builder的概念,而不是手动操作。请浏览以下链接
    <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>