Linking a css file breaks html table format - html

I am working on some Java Servlets, and basically i am outputting the results of an sql query to a table. I have some basic formatting for the table in the html code, but i also want to link a css file.
Whenever i link a stylesheet (even a blank one, or one with the same attributes as the html tags in the table), it just destroys any formatting in the table, and outputs the results as one continuous list.
Any suggestions at all would be a great help.
Here's my servlet code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String category = request.getParameter("categoryname");
AlbumDAO albumData = new AlbumDAO();
ArrayList<AlbumBean> albums = albumData.findFromCategory(category);
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String title = category + " albums";
String stylesheet = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/CSS/stylesheet.css>";
out.println("<!DOCTYPE html><html>");
out.println("<head>");
out.println("<title>" + title + "</title>");
out.println(stylesheet);
out.println("</head>");
out.println("<body>");
out.println("<Center><H1>" + category + " albums</Center>");
out.println("<table border=\"1\" cellspacing=\"5\" cellpadding=\"5\">"
+ "<tr><th>ID</th><th>Artist</th><th>Title</th><th>Image Name</th><th>Tracks</th><th>Price</th><th>In Stock</th></tr>");
for (AlbumBean a : albums){
out.println("<tr><td> "+ a.getRecording_id() + "</td>");
out.println("<td>" + a.getArtist_name() + "</td>");
out.println("<td> " + a.getTitle() + "</td>");
out.println("<td> " + a.getCategory() + "</td>");
out.println("<td> " + a.getImage_name() + "</td>");
out.println("<td> " + a.getPrice() + "</td>");
out.println("<td> " + a.getStock_count() + "</td>");
out.println("</tr>");
}
out.println("</table>");
out.println("</body>");
out.println("<footer> let's go home</footer>");
out.println("</html>");
}

Looks like you are not closing the quotation marks in your link statement
String stylesheet = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/CSS/stylesheet.css\">";

I eventually solved it, the only thing was that i was thinking the folder CSS needed to be referenced as "/CSS/stylesheet.css"
whereas it was actually just "CSS/stylesheet.css" .
Thanks guys.

Related

ClientTemplate expression to include javascript conditional

Have been using Kendo UI MVC for a while now and need to put some conditional logic on a checkbox that is in one field of the grid.
The fields in the grid that need to be evaluated are
Going off the example here
https://docs.telerik.com/aspnet-mvc/helpers/grid/faq#how-to-display-checkboxes-in-ajax-bound-grids
columns.Bound(p => p.ProductName).ClientTemplate(
"# if (HasIcon == true) { #" +
"<img src='" + Url.Content("~/Content/icons/") + "#= ProductID #.png' alt='#= ProductName # icon' />" +
"# } else { #" +
"#: ProductName #" +
"# } #"
);
How do I format the test within the conditional to use a grid field value ?
eg testing if ProductID is a specific value like this?
columns.Bound(p => p.ProductName).ClientTemplate(
"# if (#= ProductID # == 123) { #" +
"<img src='" + Url.Content("~/Content/icons/") + "#= ProductID #.png' alt='#= ProductName # icon' />" +
"# } else { #" +
"#: ProductName #" +
"# } #"
);
due to the sometimes complex nature of client templates, I personally tend to use the javascript function method
columns.Bound(p => p.ProductName).ClientTemplate("#= getProductIcon(data,
Url.Content("~/Content/icons/")#);
then in a js script block
function getProductIcon(data, imgUrl) {
if (data.ProductID == 123)
return "<img src='" + imgUrl + data.ProductID + ".png' alt='" + data.ProductName + " icon' />";
else
return data.ProductName;
}
just make sure your script is loaded before the grid is instantiated otherwise you'll run into getProductIcon undefined or some similar error. Also it's easier to throw a debugger on your javascript function and really see what's going on and verify the data in/out.
Excuse any typos in the above, I'm not at a location where I can validate the razor syntax at the moment.

Since set-cookie has been deprecated is there a way to STILL make it work (compatibility?)

On an existing web site we have many page using
<meta http-equiv="set-cookie" content="cookiename=value; expires=Fri, 22-Sep-17 08:57:01 GMT; path=/">
Set-cookie has been deprecated in chrome (see below), is there a way to keep compatibility (without change in code) ? At least temporally until correcting every place it's in use...
It seems there is no way to avoid deprecation.
The best on the EXISTING site is to change the meta by a script tag (goal is to minimize change):
REM {update expires date:1 month};
AdjDate := #Adjust(#Now;0;1;0;0;0;0);
Months:="Jan":"Feb":"Mar":"Apr":"May":"Jun":"Jul":"Aug":"Sep":"Oct":"Nov":"Dec";
Days:="Sunday":"Monday":"Tuesday":"Wednesday":"Thursday":"Friday":"Saturday";
Time := #Right("0"+#Text(#Hour(AdjDate));2) + ":" + #Right("0"+#Text(#Minute(AdjDate));2) + ":" + #Right("0"+#Text(#Second(AdjDate));2);
ExpDate := Days[#Weekday(AdjDate)] + ", " + #Right("0"+#Text(#Day(AdjDate));2) + "-" + Months[#Month(AdjDate)] + "-" + #Text(#Year(AdjDate)) + " " + Time + " GMT";
"<script type=\"text/javascript\" id=\"set-cookieJS\">document.cookie = \"" + cookiename + "=" + CartID + "; expires=" + ExpDate + "; path=/\";</script>";
The existing site is in Domino using Formula.

Show local image in WebView

I'm successfully using the WebView control to render a HTML string that I'm parsing to it... It's rendering my CSS, H1, and paragraph content perfectly.
Then, I tried to add an image tag and load in an image that is already stored locally on the phone. But it can't see to find or render the image in the WebView. How do I display locally stored images in the WebView?
Here's what I have tried:
string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
string localFilename = "project-" + ProjectId + ".png";
string localPath = "file://" + Path.Combine(documentsPath, localFilename);
string FinalHtml =
"<html><head><style>a, h1 {color:#6fb731;} h1{font-size: 1.4em;} p, body{color:#333333;}</style></head><body>" +
"<img src=\"" + localPath + "\" />" +
"<h1>" + ProjectName + "</h1>" + ProjectHtml +
"</body></html>";
ProjectsWebView.LoadData(FinalHtml, "text/html", "UTF-8");

Mix html and code asp.net

I'm trying to join two strings but I want them to be divided by a break line.
This is my code:
<td>#(string.Join("<br /> ", report.TimeReportProjects.Select(x => x.Project.ProjectName)))</td>
<td>#(string.Join("<br /> ", report.TimeReportProjects.Select(x => x.Description.Shorten(35))))</td>
<td>#(data.StartHour + ":" + data.StartMinute.ToString("00") + " - " + data.EndHour + ":" + data.EndMinute.ToString("00"))</td>
<td>#(Math.Floor(hours) + ":" + TimeSpan.FromHours(hours).Minutes.ToString("00"))</td>
The "br/>" tag will just be read as a string which is not to strange I assume, I know if i want to mix html code in a code block I should use #: but I am not sure how to use that in this case.
There is a Html.Raw method that should help you. It can be applied like so:
<td>#Html.Raw(string.Join("<br />", report.TimeReportProjects.Select(x => x.Project.ProjectName)))</td>

Doesn't show the android email html format when receive outlook

doesnt show the html format in outlook. please do reply me. sorry for the english
private void sendEmail() {
try {
String value = "<table>" +
"<tr>" +
"<td><b>Name </b></td>" +
"<td>android</td>" +
"</tr><br>" +
"<tr>" +
"<td><b>Version</b></td>" +
"<td>2.2</td>" +
"</tr>" +
"</table>";
Intent email_intent = new Intent(Intent.ACTION_SEND);
email_intent.setType("text/html");
email_intent.putExtra(Intent.EXTRA_SUBJECT, "android Details");
email_intent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(value));
email_intent.setType("vnd.android.cursor.dir/email");
startActivity(Intent.createChooser(email_intent,"Sending mail.."));
}catch(Exception e) {
}
}
You have two setType() calls. Eliminate the second. Leave the email_intent.setType("text/html") there. See if that helps.
The <table>tag is apparently not supported by android jet See this link.
I'm also trying to show a table in an E-mail but I haven't succeeded jet.