Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

"Type mismatch: cannot convert from Cookie to String"

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've searched for several examples of how to use a cookie in a form to remember the username. All of them seem to use the exact same code example. I wrote my page based on that code and I still get the following error message, "Type mismatch: cannot convert from Cookie to String" on line 42.

Any suggestions on how I should proceed? Thanks everyone.

 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you are trying to assign a Cookie instance to a String reference, so yes, you can't do that.

If you want the value of the cookie, check its javadoc to see how to get that.
 
Bear Bibeault
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And for the love of all that is good, update your JSP knowledge! Using Java code in a JSP is a bad bad practice that is almost a decade out of date!

It's no longer 2001 -- time to stop writing JSP as if it is.
 
John Piper
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Well, you are trying to assign a Cookie instance to a String reference, so yes, you can't do that.



Yea, unfortunately I'm realizing that now.

I've been trying to follow examples like these:
  • http://www.java-forums.org/java-tips/5425-jsp-cookies-example.html
  • http://www.roseindia.net/answers/viewqa/Java-Beginners/12141-Remember-me-on-this-computer-%28via-cookies%29-in-jsp-servlet.html


  • But apparently they are wrong.

    Bear Bibeault wrote:And for the love of all that is good, update your JSP knowledge! Using Java code in a JSP is a bad bad practice that is almost a decade out of date!

    It's no longer 2001 -- time to stop writing JSP as if it is.



    I'm just now starting to learn, so there isn't really anything to update

    What is considered the correct practice currently?



     
    Bear Bibeault
    Marshal
    Posts: 67418
    173
    Mac Mac OS X IntelliJ IDE jQuery Java
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    roseindia.com is generally considered a poor place to get examples from.

    With regards to modern practices: no Java code in JSP. None Zero. Nada.

    Rather, learn the JSTL and EL.

    As a beginner, I recommend this article and this article to help get you started.
     
    He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic