Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 971215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:55:38+00:00 2026-05-16T02:55:38+00:00

I have a servlet coded in Scala. I have some code like this in

  • 0

I have a servlet coded in Scala. I have some code like this in there:

def message = <HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>{value}</BODY></HTML>
def value = "Hello <BR/> World"

The corresponding HTML code generated for value is

Hello &lt;BR/&gt; World

How do I get it to generate the HTML code (shown below)?

Hello <BR/> World

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:55:38+00:00Added an answer on May 16, 2026 at 2:55 am

    If you don’t mind changing the type of value to xml.Elem, you can do

    def value = <xml:group>Hello <BR/> World</xml:group>
    

    Addition

    In my opinion, you should type as much XML inline as possible. Only then will you have compile time validation of the input. All other solutions either give you a runtime exception at some point (say, you forgot some /) or might even break your XML layout.

    However, if you really want to have an easy transform, you could do this:

    class XmlString(str: String) {
      def assumeXML = xml.XML.loadString("<xml:group>" + str + "</xml:group>")
      def toUnparsedXML = new xml.Unparsed(str)
    }
    implicit def stringToXmlString(str: String) = new XmlString(str)
    
    def value = "Hello <BR/> World"
    

    and then (for some reason, it still shows the <xml:group> part; you could get rid of it with xml.NodeSeq.fromSeq(value.assumeXML.child) or similar)

    def message = <HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>{value.assumeXML}</BODY></HTML>
    

    or even (well, you would not need the implicit here, Unparsed(value) would do)

    def message = <HTML><HEAD><TITLE>Test</TITLE></HEAD><BODY>{value.toUnparsedXML}</BODY></HTML>
    

    The assumeXML method will fail with at runtime, if you provide invalid XML; toUnparsedXML will accept all input, even data that is potentially dangerous.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have Servlet code like, PrintWriter out = response.getWriter(); out.println(<html>); out.println(<head>); out.println(<title>Hi</title>); out.println(</head>); out.println(<body>);
I have written this code inside a servlet to delete certain records from three
I have the following scala code: package dummy import javax.servlet.http.{HttpServlet, HttpServletRequest => HSReq, HttpServletResponse
I have this Servlet code, I am trying to check for duplicate usernames in
I have the following JSP File and Servlet file <html> <head> <meta http-equiv=Content-Type content=text/html;
In my servlet I have the following code: response.setContentType(application/json);//set json content type PrintWriter out
I have a servlet that does some business login and then redirects to a
I have a servlet which takes us to an existing jsp, say home.jsp. This
I have this servlet program and an external .jar file (written by someone else)
Sorry about the vague title but I have a servlet with the following mapping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.