This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JSP and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark ""Unterminated <c:out tag" Error" Watch ""Unterminated <c:out tag" Error" New topic
Author

"Unterminated <c:out tag" Error

R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
Hi everybody,
I have this piece of code in a JavaScript function #1, and try to call the charCounter() function from within #1. Receive the above error on the 5th line. Does anyone have any idea? any help is greatly appreciated.


R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
Sorry, I received the error from within a JavaScript function, so thought its a JavaScript issue!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

What is the charCounter() function? JavaScript?

If so, you can't mix JavaScript and JSP in this manner. Remember that JSPis evaluated on the server to format an HTML page to send to the browser. Once the browser has the HTML page, it evaluates the JavaScript in the page.

Please read this article to understand how JSP operates.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

R Naijat wrote:Sorry, I received the error from within a JavaScript function, so thought its a JavaScript issue!

<c:out> is JSP and has nothing to do with JavaScript as you will discover upon reading the article.
R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
charCounter() is a JavaScript function which I posted below. The lines of code which give me the error, is within another JavaScript function. I'm trying to call charCounter() function from within the first JavaScript function.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

Read the article. You are trying to mix JavaScript into JSP and that just can't happen.
R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
This is the original line which works properly. All I'm trying to do is to control the length of the filed, with the charCounter function instead of using the maxlength property. So I used <c:out b/c it was already being used and is working.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

It works because it understands that the JSP portions are evaluated and substituted on the server and simply inserted into the template to create a valid HTML page to send to the browser. You'll note that it does assume that the JSP and that the JavaScript will be evaluated at the same time and on the same machine.
R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
Right, I removed the c:out tags and tried to call the charCounter() function directly. Now I do not receive any error, but the portion of the page which is supposed to display the Title filed, does not do anything! Since its a JavaScript issue, I will create a topic in JavaScript postings.
R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
Btw, meanwhile am reading the article you mentioned, thanks!
R Naijat
Ranch Hand

Joined: Nov 01, 2011
Posts: 40
Per Bear I'm back to this topic again...

I removed the c:out tags and now I do not receive the original Unterminated tag error anymore. This is the part of code which I'm trying to control the Title filed with the charCounter() function. I receive this error:

The function charCounter must be used with a prefix when a default namespace is not specified.

Any idea?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

At this point I have no idea what you are really trying to accomplish. Just removing the <c:out> tags isn't what I was talking about. The <c:out> tags were (I assume) there to provide server-side values to be injected into the markup at certain points. If you can just remove them, what was the point of their being there in the first place?

I'm still not convinced that you understand what JSP is and how it works.

So is the problem that:
  • The JSP isn't compiling because of syntax error in using the <c:out> tags?

  • Or is it that:
  • There are client-side errors after the HTML page is delivered to the browser?
  • R Naijat
    Ranch Hand

    Joined: Nov 01, 2011
    Posts: 40
    I already have a Title filed which is being controlled within a JavaScript function as follows and it works properly; the length of this filed is controlled by maxlength html property.

    Lets call this #1:



    This is what Im trying to accomplish:
    I need to get rid of this maxlenght html property and instead call the charCounter() function in order to let user know that how many chars he already entered and how many chars left. The charCounter() receives three fields: (field, count, max).

    Filed: the Title field
    Count: another field which let the user know how many chars left
    Max: the max number of chars allowed.

    So I tried to modify #1 - as following code - to call the charCounter() function. Also created the $left variable to send to charCounter() as count argument.

    And now I receive this error:

    The function charCounter must be used with a prefix when a default namespace is not specified




    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60082
        
      65

    It's still clear that you don't understand how a JSP template works. For example, you don't need to use JavaScript string concatenation.

    Let's say that that you had a JSP scoped variable named xyz that had the value "whatever" in it, and you wanted to embed it inside a JavaScript string. That should look like:


    Note that there is no + operator anywhere in sight!

    After the JSP executes, what gets sent to the browser as part of the response will be:


    The JSP <c:out> tag is substituted in place when the JSP executes.

    That should help simplify your markup considerably. What you have now is not only overly complex, but won't result in valid JavaScript syntax being generated.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: "Unterminated &lt;c:out tag" Error
     
    Similar Threads
    Attach eventListener to objects
    Calling a JavaScript function from within another JavaScript function
    jsp insert program not working
    Uncaught TypeError: Cannot read property 'length' of undefined
    Need Help With Dynamic text box in JSP