0

无法使用 glass fish server3.1.2 在 netbeans 中编译 jsp,它显示以下异常

org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
not a statement

PWC6197: An error occurred at line: 9 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
';' expected

我的 java 和 jsp 代码

<%@page contentType="text/html" pageEncoding="UTF-8" %>
<%@page language="java" import= "java.sql.*"%>
<%
String driver="org.postgresql.Driver";
Class.forName(driver).newInstance();
Connection con=null;
ResultSet rst=null;
Statement stmt=null;
try
{
  String url="jdbc:postgresql://localhost:5432/ksa?user="postgres"password="postgres"";
  con=DriverManager.getConnection("url");
  stmt=con.createStatement();
}          
catch(Exception e)
               {
  System.out.println(e.getMessage());
       }
if(request.getParameter("action")!=null)
       {
           String name=request.getParameter("name");
           String address=request.getParameter("address");
           String id=request.getParameter("id");
           stmt.executeUpdate("insert into cd values('"+ name +"','"+ address +"')");
           rst=stmt.executeQuery("select * from cd");             
       }    
%>

netbeans 显示该行中的错误

String url="jdbc:postgresql://localhost:5432/ksa?user="postgres"password="postgres"";

我使用 postgresql9.1,glassfish 日志显示以下内容

SEVERE: Error compiling file: /home/adapco/.netbeans/7.1.1/config/GF3_1/domain1  /generated/jsp/cddata/org/apache/jsp/index_jsp.java
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
4

2 回答 2

0

该行不正确:

String url="jdbc:postgresql://localhost:5432/ksa?user="postgres"password="postgres";

它应该是:

String url="jdbc:postgresql://localhost:5432/ksa?user=\"postgres\"&password=\"postgres\"";

更新:

顺便一提:

con=DriverManager.getConnection("url");

应该:

con=DriverManager.getConnection(url);
于 2012-04-17T10:25:01.410 回答
0

我认为这是一个小错误,您的“{”和“}”不匹配,我遇到了同样的问题。

于 2017-06-05T07:58:19.393 回答