2012-11-19 3 views
1

양식에서 데이터를 검색하고 JDBC를 통해 MySQL 데이터베이스로 보내는 방법은 무엇입니까?기본 양식 포틀릿 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는 내가 틀렸다고 말합니다.

올바른 저장 절차는 무엇입니까?

+0

이 유 http://www.liferay.com/community/wiki/ 링크를 통해 이동 manually..please 그 일을 대신이에 대한 서비스 빌더의 개념을 사용할 수 있습니다 .... 당신입니다 -/wiki/Main/How + + + + 데이터베이스 + 포틀릿 생성 – Gautam

답변

0

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!">  

0

form 태그의 action 속성의 값을 확인하시기 바랍니다.

여러 가지 방법으로 사용할 수 있습니다.

<form method="post" action="<%=Invio%>"> 
     <input type="text" name="username"> 
     <input type="password" name="password"> 
     <input type="submit" value="Invia!">  
    </form> 

내가 좋아하지 않는 셋째 하나

3.

<form method="post" action="${Invio}"> 
     <input type="text" name="username"> 
     <input type="password" name="password"> 
     <input type="submit" value="Invia!">  
    </form> 

2

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

선택은