Forum Moderators: phranque

Message Too Old, No Replies

Dreamweaver add record

JSP syntax error - any Java Nuts out there?

         

delboy1978uk

2:12 pm on Jul 29, 2005 (gmt 0)

10+ Year Member



hi there
i have a page for adding a contact in jsp
the page is sent the supplier name from the supplier table via url parameter
the user fills in the form with contact details etc
there is a hidden field with the value of the supplier name, so that when you submit, the contact in the contacts table is linked with the supplier, without you having to retype the supplier name. Should have been simple enough, but this is what I got:
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 3 in the jsp file: /addcontact.jsp
Generated servlet error:
Syntax error on token ";", delete this token

An error occurred at line: 3 in the jsp file: /addcontact.jsp
Generated servlet error:
Syntax error on token ";", . expected

An error occurred at line: 3 in the jsp file: /addcontact.jsp
Generated servlet error:
Syntax error on token ";", delete this token

An error occurred at line: 3 in the jsp file: /addcontact.jsp
Generated servlet error:
Syntax error on token ";", . expected

org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:397)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Can anyone help?

txbakers

3:56 am on Jul 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can you post some of the JSP code? the error messages don't help debug this one.

delboy1978uk

1:12 pm on Aug 1, 2005 (gmt 0)

10+ Year Member



managed to fix that page but i have another page with the exact same error - here is the code:

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %>
<%
// *** Logout the current user.
String MM_Logout = request.getRequestURI() + "?MM_Logoutnow=1";
if (request.getParameter("MM_Logoutnow")!= null &amp;&amp; request.getParameter("MM_Logoutnow").equals("1")) {
session.putValue("MM_Username", "");
session.putValue("MM_UserAuthorization", "");
String MM_logoutRedirectPage = "index.jsp";
// redirect with URL parameters (remove the "MM_Logoutnow" query param).
if (MM_logoutRedirectPage.equals("")) MM_logoutRedirectPage = request.getRequestURI();
if (MM_logoutRedirectPage.indexOf("?") == -1 &amp;&amp; request.getQueryString()!= null) {
String MM_newQS = request.getQueryString();
String URsearch = "MM_Logoutnow=1";
int URStart = MM_newQS.indexOf(URsearch);
if (URStart >= 0) {
MM_newQS = MM_newQS.substring(0,URStart) + MM_newQS.substring(URStart + URsearch.length());
}
if (MM_newQS.length() > 0) MM_logoutRedirectPage += "?" + MM_newQS;
}
response.sendRedirect(response.encodeRedirectURL(MM_logoutRedirectPage));
return;
}
%>
<%@ include file="Connections/local_connection.jsp" %>
<%@ include file="Connections/local_connection.jsp" %>
<%
// *** Edit Operations: declare variables

// set the form action variable
String MM_editAction = request.getRequestURI();
if (request.getQueryString()!= null && request.getQueryString().length() > 0) {
MM_editAction += "?" + request.getQueryString();
}

// connection information
String MM_editDriver = null, MM_editConnection = null, MM_editUserName = null, MM_editPassword = null;

// redirect information
String MM_editRedirectUrl = null;

// query string to execute
StringBuffer MM_editQuery = null;

// boolean to abort record edit
boolean MM_abortEdit = false;

// table information
String MM_editTable = null, MM_editColumn = null, MM_recordId = null;

// form field information
String[] MM_fields = null, MM_columns = null;
%>
<%
// *** Update Record: set variables

if (request.getParameter("MM_update")!= null &&
request.getParameter("MM_update").toString().equals("form1") &&
request.getParameter("MM_recordId")!= null) {

MM_editDriver = MM_local_connection_DRIVER;
MM_editConnection = MM_local_connection_STRING;
MM_editUserName = MM_local_connection_USERNAME;
MM_editPassword = MM_local_connection_PASSWORD;
MM_editTable = "creative.contacts";
MM_editColumn = "contactid";
MM_recordId = "" + request.getParameter("MM_recordId") + "";
MM_editRedirectUrl = "contactupdated.jsp";
String MM_fieldsStr = "name¦value¦dept¦value¦email¦value¦phone¦value";
String MM_columnsStr = "name¦',none,''¦dept¦',none,''¦email¦',none,''¦phone¦',none,''";

// create the MM_fields and MM_columns arrays
java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_fieldsStr,"¦");
MM_fields = new String[tokens.countTokens()];
for (int i=0; tokens.hasMoreTokens(); i++) MM_fields[i] = tokens.nextToken();

tokens = new java.util.StringTokenizer(MM_columnsStr,"¦");
MM_columns = new String[tokens.countTokens()];
for (int i=0; tokens.hasMoreTokens(); i++) MM_columns[i] = tokens.nextToken();

// set the form values
for (int i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = ((request.getParameter(MM_fields[i])!=null)?(String)request.getParameter(MM_fields[i]):"");
}

// append the query string to the redirect URL
if (MM_editRedirectUrl.length()!= 0 && request.getQueryString()!= null) {
MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + request.getQueryString();
}
}
%>
<%
// *** Update Record: construct a sql update statement and execute it

if (request.getParameter("MM_update")!= null &&
request.getParameter("MM_recordId")!= null) {

// create the update sql statement
MM_editQuery = new StringBuffer("update ").append(MM_editTable).append(" set ");
for (int i=0; i+1 < MM_fields.length; i+=2) {
String formVal = MM_fields[i+1];
String elem;
java.util.StringTokenizer tokens = new java.util.StringTokenizer(MM_columns[i+1],",");
String delim = ((elem = (String)tokens.nextToken())!= null && elem.compareTo("none")!=0)?elem:"";
String altVal = ((elem = (String)tokens.nextToken())!= null && elem.compareTo("none")!=0)?elem:"";
String emptyVal = ((elem = (String)tokens.nextToken())!= null && elem.compareTo("none")!=0)?elem:"";
if (formVal.length() == 0) {
formVal = emptyVal;
} else {
if (altVal.length()!= 0) {
formVal = altVal;
} else if (delim.compareTo("'") == 0) { // escape quotes
StringBuffer escQuotes = new StringBuffer(formVal);
for (int j=0; j < escQuotes.length(); j++)
if (escQuotes.charAt(j) == '\'') escQuotes.insert(j++,'\'');
formVal = "'" + escQuotes + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_editQuery.append((i!=0)?",":"").append(MM_columns[i]).append(" = ").append(formVal);
}
MM_editQuery.append(" where ").append(MM_editColumn).append(" = ").append(MM_recordId);

if (!MM_abortEdit) {
// finish the sql and execute it
Driver MM_driver = (Driver)Class.forName(MM_editDriver).newInstance();
Connection MM_connection = DriverManager.getConnection(MM_editConnection,MM_editUserName,MM_editPassword);
PreparedStatement MM_editStatement = MM_connection.prepareStatement(MM_editQuery.toString());
MM_editStatement.executeUpdate();
MM_connection.close();

// redirect with URL parameters
if (MM_editRedirectUrl.length()!= 0) {
response.sendRedirect(response.encodeRedirectURL(MM_editRedirectUrl));
return;
}
}
}
%>
<%
// *** Restrict Access To Page: Grant or deny access to this page
String MM_authorizedUsers="";
String MM_authFailedURL="notlogged.jsp";
boolean MM_grantAccess=false;
if (session.getValue("MM_Username")!= null &&!session.getValue("MM_Username").equals("")) {
if (true ¦¦ (session.getValue("MM_UserAuthorization")=="") ¦¦
(MM_authorizedUsers.indexOf((String)session.getValue("MM_UserAuthorization")) >=0)) {
MM_grantAccess = true;
}
}
if (!MM_grantAccess) {
String MM_qsChar = "?";
if (MM_authFailedURL.indexOf("?") >= 0) MM_qsChar = "&";
String MM_referrer = request.getRequestURI();
if (request.getQueryString()!= null) MM_referrer = MM_referrer + "?" + request.getQueryString();
MM_authFailedURL = MM_authFailedURL + MM_qsChar + "accessdenied=" + java.net.URLEncoder.encode(MM_referrer);
response.sendRedirect(response.encodeRedirectURL(MM_authFailedURL));
return;
}
%>
<%
String loggeduser__MMColParam = "1";
if (session.getValue("MM_Username")!=null) {loggeduser__MMColParam = (String)session.getValue("MM_Username");}
%>
<%
Driver Driverloggeduser = (Driver)Class.forName(MM_local_connection_DRIVER).newInstance();
Connection Connloggeduser = DriverManager.getConnection(MM_local_connection_STRING,MM_local_connection_USERNAME,MM_local_connection_PASSWORD);
PreparedStatement Statementloggeduser = Connloggeduser.prepareStatement("SELECT username FROM creative.staff WHERE username = '" + loggeduser__MMColParam + "'");
ResultSet loggeduser = Statementloggeduser.executeQuery();
boolean loggeduser_isEmpty =!loggeduser.next();
boolean loggeduser_hasData =!loggeduser_isEmpty;
Object loggeduser_data;
int loggeduser_numRows = 0;
%>
<%
String rscontact__MMColParam = "1";
if (request.getParameter("contactid")!=null) {rscontact__MMColParam = (String)request.getParameter("contactid");}
%>
<%
Driver Driverrscontact = (Driver)Class.forName(MM_local_connection_DRIVER).newInstance();
Connection Connrscontact = DriverManager.getConnection(MM_local_connection_STRING,MM_local_connection_USERNAME,MM_local_connection_PASSWORD);
PreparedStatement Statementrscontact = Connrscontact.prepareStatement("SELECT * FROM creative.contacts WHERE contactid = " + rscontact__MMColParam + "");
ResultSet rscontact = Statementrscontact.executeQuery();
boolean rscontact_isEmpty =!rscontact.next();
boolean rscontact_hasData =!rscontact_isEmpty;
Object rscontact_data;
int rscontact_numRows = 0;
%>

<html><!-- InstanceBegin template="/Templates/menu.dwt.dwt.jsp" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Untitled Document</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<link href="Templates/text.css" rel="stylesheet" type="text/css">
<!-- InstanceEndEditable -->

<link href="text" rel="stylesheet" type="text/css">
<link href="text.css" rel="stylesheet" type="text/css">
</head>

<body bgcolor="#000028" text="#000000" link="#000099" vlink="#0033FF" alink="#0000FF">
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="35" height="109" background="frames/logoleft.gif">&nbsp;</td>
<td width="139" height="109" background="frames/logomain.gif">&nbsp;</td>
<td width="187" height="109" background="frames/topfiller.gif">&nbsp;</td>
<td width="77" height="109" background="frames/esrlogo.gif">&nbsp;</td>
<td width="188" height="109" background="frames/topfiller.gif">&nbsp;</td>
<td width="139" height="109" valign="top" background="frames/topfiller.gif">
<div align="right"><font color="#FFFFFF" size="-7" face="tahoma">Welcome,
<%=(((loggeduser_data = loggeduser.getObject("username"))==null ¦¦ loggeduser.wasNull())?"":loggeduser_data)%> </font><br>
<font color="#FFFFFF" size="-4" face="tahoma"><a href="<%= MM_Logout %>">Log
out</a></font></div></td>
<td width="35" height="109" background="frames/logoright.gif">&nbsp;</td>
</tr>
<tr>
<td width="35" height="35" background="frames/nw.gif">&nbsp;</td>
<td height="35" colspan="5" valign="top" background="frames/n.gif">
<div align="center">
<table width="338" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="35" valign="top"><div align="center"><font color="#FFFFFF" size="-1" face="tahoma"><a href="suppliers.jsp"><font color="#FFFFFE">Suppliers</font></a>
¦ <a href="logistics.jsp"><font color="#FFFFFE">Logistics</font></a>
¦ <a href="admin.jsp"><font color="#FFFFFE">Admin</font></a><br>
</font></div></td>
</tr>
</table>


</div></td>
<td width="35" height="35" background="frames/ne.gif">&nbsp;</td>
</tr>
<tr>
<td width="35" background="frames/w.gif">&nbsp;</td>
<td colspan="5" bgcolor="#FFFFFF"><!-- InstanceBeginEditable name="EditRegion3" --><span class="header"><%=(((rscontact_data = rscontact.getObject("suppname"))==null ¦¦ rscontact.wasNull())?"":rscontact_data)%></span>
<div align="center">
<div align="center">
<p class="text"><font color="#000066"><strong>Edit Contact</strong></font></p>
</div>
<form method="post" action="<%=MM_editAction%>" name="form1">
<table align="center">
<tr valign="baseline" class="text">
<td align="right" nowrap>Name</td>
<td> <input type="text" name="name" value="<%=(((rscontact_data = rscontact.getObject("name"))==null ¦¦ rscontact.wasNull())?"":rscontact_data)%>" size="32"> </td>
</tr>
<tr valign="baseline" class="text">
<td align="right" nowrap>Dept.</td>
<td> <input type="text" name="dept" value="<%=(((rscontact_data = rscontact.getObject("dept"))==null ¦¦ rscontact.wasNull())?"":rscontact_data)%>" size="32"> </td>
</tr>
<tr valign="baseline" class="text">
<td align="right" nowrap>Email</td>
<td> <input type="text" name="email" value="<%=(((rscontact_data = rscontact.getObject("email"))==null ¦¦ rscontact.wasNull())?"":rscontact_data)%>" size="32"> </td>
</tr>
<tr valign="baseline" class="text">
<td align="right" nowrap>Phone</td>
<td> <input type="text" name="phone" value="<%=(((rscontact_data = rscontact.getObject("phone"))==null ¦¦ rscontact.wasNull())?"":rscontact_data)%>" size="32"> </td>
</tr>
<tr valign="baseline" class="text">
<td align="right" nowrap>&nbsp;</td>
<td> <div align="right">
<input type="submit" value="Update &gt;&gt;">
</div></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form1">
<input type="hidden" name="MM_recordId" value="<%=(((rscontact_data = rscontact.getObject("contactid"))==null ¦¦ rscontact.wasNull())?"":rscontact_data)%>">
</form>

</div>
<!-- InstanceEndEditable --></td>
<td width="35" background="frames/e.gif">&nbsp;</td>
</tr>
<tr>
<td height="35" colspan="7"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="222" height="35" background="frames/sw.gif">&nbsp;</td>
<td height="35" background="frames/s.gif">&nbsp;</td>
<td width="35" height="35" background="frames/se.gif">&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
</body>
<!-- InstanceEnd --></html>
<%
loggeduser.close();
Statementloggeduser.close();
Connloggeduser.close();
%>
<%
rscontact.close();
Statementrscontact.close();
Connrscontact.close();
%>