Solved

JSP / Struts Questions - I want to use HTML in Java String???  JSP renders the HTML, rather than displaying it

Posted on 2003-11-16
4
276 Views
Last Modified: 2010-04-01
I have an access database with a bunch of text values in it.  The user selects specific search criteria, like name, make or model, then submits the page.  The page, if it passes the forms' validate method, goes to the action, where methods determine which specific query to run.  A service is run (think model of the MVC) where the resultset is created and used to populate each value in a resultBean.  The resultBean's are then added to a Vector and, after going through the entire resultset, returned to the calling method in the Action.  The resulting Vector is placed into the request object and returned to the 'success' page.

What I'd LIKE to do, is set up so that the specific search criteria that the user has entered is made red (<font color='red'>Search Criteria</font>).  To be more specific, if the user selected Model=XYZ, Manufacturer=ABC, I'd like the application to highlight ABC and XYZ in ALL of the corresponding results in the JSP success page.  I am having a bunch of difficulty with this though.  I've tried to append the html commands onto the string before populating the corresponding value in the resultBean, but the JSP page displays the html as a literal string.  ie. Model=<font color='red'>XYZ</font>

How / where would I create my html tags to highlight the specific search criteria that the user entered??

I thought about doing it in the JSP success page, but all I'm doing there is logic:iterate'ing through the collection that is returned in the request object...Any and all help on this is GREATLY appreciated!  Thanks in advance to all the experts...
0
Comment
Question by:ShaymusBane2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:JNic
ID: 9760031
Hi Shaymus.

If I understand your question correctly, you want to create a dynamic form page.

For me, the solution to doing this, is to sometimes skip the use of tags .

You can fx. do like this:

<%
String color="red"; // change this to the color you want.
String test="<font color='"+color+"'>XYZ</font>";
out.println(test);
%>

This will append your String as html on your jsp.

So simply get your bean-values and construct a String containing the right HTML-output, and then out.println() the String.

Hope this helps, otherwise please clarify your question further.

Regards,

Nic
 
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 75 total points
ID: 9760208
welcome to EE, ShaymusBane!
the struts <bean:write> tag will by default converts special character to html entity, for example '<' to '&lt;'. this end up with your html code displayed as is.

You can simply set filter attribute to false: <bean:write filter="false" ..../>
0
 

Author Comment

by:ShaymusBane2
ID: 9760329
That was EXACTLY what I was looking for kennethxu!!!  Thank you very very very much!

Thanks for the suggestion JNic, but I what kennethxu suggested is exactly what I was looking to do.
0
 
LVL 1

Expert Comment

by:JNic
ID: 9760372
Kennethxu is the man with the plan around here!  ;-)
I try to help the best I can, - but its always better when somebody has a better suggestion.
Glad you got your problem solved!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
dynamic reloading of jsp in jetty 2 121
Looking for some programs to resell or buy source codes 1 78
maven j2ee examles 2 64
throw exception 21 69
Always backup Domain, SYSVOL etc.using processes according to Microsoft Best Practices. This is meant as a disaster recovery process for small environments that did not implement backup processes and did not run a secondary domain controller that ne…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

696 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