我正在运行此代码,但它不起作用。我正在将 Glassfish 与 eclipse 一起使用 无法使用 GlassFish Server Open Source Edition 3.1.2.2 编译 jsp,它显示以下异常 这里是代码
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java" import="java.sql.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>GlassFish JSP Page</title>
</head>
<body>
<%
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection C =DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","");
} catch (Exception E) {
System.err.println("Unable to load driver.");
E.printStackTrace();
}
try{
Statement stmt=null;
int val=stmt.executeUpdate("insert into reg(Name,Fname) values('"+haroon+"','"+hussain+"')");
if(val==1){
System.out.println("Data has been inserted :)");
}else {
System.out.println("data has not been inserted. :( ");
}
} catch (Exception e) {
e.printStackTrace();
System.out.println("Cant inserted");
}
%>
</body>
</html>
glassfish 显示异常
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP
PWC6197: An error occurred at line: 15 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:72: cannot find symbol
symbol : variable haroon
location: class org.apache.jsp.index_jsp
PWC6197: An error occurred at line: 15 in the jsp file: /index.jsp
PWC6199: Generated servlet error:
string:///index_jsp.java:72: cannot find symbol
symbol : variable hussain
location: class org.apache.jsp.index_jsp
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.
请任何人解决这个问题
最佳答案
您正在使用变量 haroon
和 hussain
并且您从未在 JSP 中声明它们。编译器无法在生成的 servlet 代码中的任何位置找到该变量。
我强烈劝阻为这些 well known various reasons 编写脚本(除非您这样做是为了学习目的) .
关于这一点,如果您将一个变量传递到您的 JSP 页面,并且您想要将它保存到您的数据库,那么这样就足够了:
<%
String haroon = request.getParameter("haroon");
String hussain = request.getParameter("hussain");
%>
(在进行数据库连接之前添加标签)。您现在可以通过在 URL(调用 JSP)上附加 2 个参数(haroon
和 hussain
)来传递值。
关于java - 组织.apache.jasper.JasperException : PWC6033: Error in Javac compilation for JSP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12518396/