Solved

Javascript not parsing correctly in JSP page

Posted on 2009-07-06
10
463 Views
Last Modified: 2012-05-07
Can someone help me out with this function?
I get this error when I run it.
I'm only including the script cause that is where the error occurs, I take it out and it works fine.

org.apache.jasper.JasperException: ServletException in '/WEB-INF/jsp/wf-useringroup-assign.jsp': /WEB-INF/jsp/wf-useringroup-assign.jsp(61,28) Element type "x.length" must be followed by either attribute specifications, ">" or "/>".
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:476)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:371)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
      org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:261)
      org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
      org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:300)
      com.docato.composer.DocatoRequestProcessor.process(DocatoRequestProcessor.java:169)
      org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
      org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
      com.docato.util.GZIPFilter.doFilter(GZIPFilter.java:40)
      com.docato.util.TidyFilter.doFilter(TidyFilter.java:33)
      com.docato.util.SchematronFilter.doFilter(SchematronFilter.java:131)
      com.docato.util.XSLTFilter.doFilter(XSLTFilter.java:199)
      com.docato.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:137)

<script type="text/javascript">

		function submitAction(action)

		{

			document.location.href=action; 	

		}
 

		function onSelectChange()

		{			

		}
 

		function getSelections(btn) 

		{

			var x = document.getElementById('frmMain');

			for (var i=0; i<x.length; i++) 

			{

				if (x[i].type.match(/select/i)) 

				{

					alert(x[i].name);

				}

			}

		}

	</script>

Open in new window

0
Comment
Question by:rotovibe
  • 5
  • 3
  • 2
10 Comments
 
LVL 4

Expert Comment

by:Tuno85
ID: 24789142
Did you close the other tags/scriptlets correctly in the rest of your JSP?
0
 

Author Comment

by:rotovibe
ID: 24789217
I believe so. I will check again.
0
 

Author Comment

by:rotovibe
ID: 24789258
All of the tags are closed. I am using JSTL for some dynamic data but it all works fine when I take out the javascript.

The script and the page render fine when I remove the for statement in the script like this:
function getSelections(btn)
{
var x = document.getElementById('frmMain');
[SNIP!!!]
}

It is complaing about the for statement. Mainly the less than sign?
0
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24791261
your html is not well formed. check for the tag attributes placed without any space between them.

eg:   <table  border="0" class="tborder"width="100%">                                


Should be

<table border="0"  class="tborder" width="100%">                                

I would say a quick way is to change ur .jsp or .html file to .xml and open in a browser to validate the well formedness of ur file.

-Murali*

0
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24791264
sorry eg: got mixed up. Here is the correct one

eg:
</table><table  border="0" class="tborder"width="100%">                                

Should be

<table border="0"  class="tborder" width="100%">  
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:rotovibe
ID: 24791353
I couldn't find any well-formed type errors.
Attached is the source code. Again, it complains about the for statement in the javascript.
Thanks for the help. I'm pulling my hair out!

<?xml version="1.0" encoding="UTF-8"?>
 

<jsp:root

   xmlns:jsp="http://java.sun.com/JSP/Page"

   xmlns:c="/tags/c"

   xmlns:logic="/tags/struts-logic"

   xmlns:bean="/tags/struts-bean"

   xmlns:html="/tags/struts-html"

   xmlns:tagx="urn:jsptagdir:/WEB-INF/tags"

   xmlns:fn="/tags/functions"

   version="1.2">

<jsp:directive.page import="com.docato.repository.XMLResource"/>
 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

	<style type="text/css">

		.dmcstyle {

			text-align: center;

			font-size: small;

		}

		

		.style1 {

			margin-left: 0px;

		}

		

		.gradient {

			background-color: #D9E1E8;

			margin: 0px;

		}

		

		.btn 

		{

			  color:#000000;

			  font: bold 84% 'trebuchet ms',helvetica,sans-serif;

			  background-color:#96A4B4;

			  border: 1px solid;

			  border-color: #696 #363 #363 #696;

			  filter:progid:DXImageTransform.Microsoft.Gradient

			  (GradientType=0,StartColorStr='#ffffffff',EndColorStr='#96A4B4');

			}

						

	</style>

	<script type="text/javascript">

		function submitAction(action)

		{

			document.location.href=action; 	

		}
 

		function onSelectChange()

		{			

		}
 

		function getSelections(btn) 

		{

			var x = document.getElementById('frmMain');

			for (var i=0; i < x.length; i++) 

			{

				if (x[i].type.match(/select/i)) 

				{

					alert(x[i].name);

				}

			}

		}

		

	</script>	

</head>
 

<body>

	<!--<tagx:insert-resource-edit-scripts/>-->

<img style="margin-bottom: -2px;" src="images/activitydetails.jpg"/>

<div class="gradient">

	<form action="CreateDataModule.do" method="post" id="frmMain" name="frmMain">

		<table style="width: 600px;">

			<tr>

				<td colspan="2">

					Please choose a user to assign for each activity.

				</td>

			</tr>

			<tr>

				<td style="border-bottom: #999999 1px solid;" >

					<strong>Activity</strong>

				</td>

				<td style="border-bottom: #999999 1px solid;" >

					<strong>User</strong>	

				</td>

			</tr>

			<c:forEach items="${activities}" var="activity" >

			<tr style="background-color: ${((loop.index % 2) == 0) ? 'whitesmoke' : '#eeeeee'};">

				<td >

					${activity.wfActivityDefinition.activityName}

				</td>

				<td>				

					<select name="${activity.wfActivityDefinition.activityName}" id="${activity.wfActivityDefinition.activityName}" onchange="onSelectChange()">

						<option value="--" >--</option>

						<c:forEach items="${namelist}" var="name">

							<option  value="${name.realName}"  >

								<c:out value="${name.realName}"/>

							</option>

						</c:forEach>

					</select>	

				</td>		

			</tr>		

			</c:forEach>

			<tr>

				<td colspan="2" >

					<button   class="btn" onclick="getSelections(this);">

						<span style="vertical-align: middle;">make assignment</span>

						<img style="vertical-align: middle;"  src="images/accept.png"/>						

					</button>&#160;

				</td>

			</tr>

			<!-- 

			<tr style="border-top : 1px solid #cccccc;">

					<c:forEach items="${nextTrans}" var="trans">

						<td valign="left" style="border: none;"></td>

						<td valign="left" style="border: none;"></td>

					</c:forEach>

			</tr>

			-->

		</table>

	</form>

</div>

<br/>

<br/>

</body>

</html>
 

</jsp:root>

Open in new window

0
 
LVL 13

Expert Comment

by:Murali Murugesan
ID: 24791773
can u try to remove jsp:root tag and map all the tlds as follows, remember to remove the end jsp:root tag as well.

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

-Murali*
0
 

Author Comment

by:rotovibe
ID: 24795040
unfortunately that is an inherited convention. I am making customizations to an existing system that uses that tag declaration format.
Works fine on the other pages. And mine does as well, except when I introduce the "<" sign in that javascript.
0
 
LVL 4

Accepted Solution

by:
Tuno85 earned 500 total points
ID: 24797741
Because you are using the jsp root tag and xml like structure, "<" sign will be seen as opening of the tag causing parsing exceptions.

What happens if you include your javascript code from a .js file.
<script type="text/javascript" src="xxx.js" />

Open in new window

0
 

Author Comment

by:rotovibe
ID: 24798451
THAT'S IT!!
The include works perfectly.
Much appreciated!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now