vbscript function to handle all my HTML header code - html

I'm creating an ASP.net website and I need to use a VBScript to handle my code using a function so that every time i call that function it writes that code in html.
Something like this:
function heading(tite){
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<title><%= title %></title>
</head>
}
How can i do this?
Thanks

<% sub heading(titl) %>
<html><head>your html here<% =titl %>
</head>
<% end sub %>
</html>

Related

how to redirect the links to a particular webpage using jsp?

There is my jsp page in which a href links are there.
So i have to redirect it to that particular web page when i click to that link.
The links are fetched from my database.
Below is my jsp page
<%# page import="java.sql.*" %>
<%ResultSet rs=null; %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
Your Searched Results Are :
</title>
<link href="Desktop/style.css" rel="stylesheet" type="text/css" />
</head>
<body bgcolor="8B4513">
<%
Connection conn=null;
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn=DriverManager.getConnection
("jdbc:mysql://localhost:3306/tendermysql","root","root");
Statement stmt=conn.createStatement();
rs=stmt.executeQuery("select * from Record");
%>
<form>
<center>
<h1> Welcome to Ezest Tender Optimzed Search</h1>
<%
while(rs.next())
{
%>
<a href= "<%rs.getString(2); %>"
onclick = "window.location.href=this.form.rs.getString(2)
[this.form.rs.getString(2)]" > <% out.println(rs.getString(2)); %>
</a>
<br />
<% } %>
<% }
catch(Exception e)
{
out.println("Wrong Input" +e);
}
%>
<br>
</center>
</form>
</body>
</html>
I tried it but the page is not redirecting...
Porblem here is that your ResultSet is forward only so you cannot use this line rs.getString(2) to get same record more than once inside loop. Use a temp variable to repeat the value. Also there is no need to give onclick attribute when href is given the same link.
String str;
while(rs.next()){
str = rs.getString(2);%>
<%=str%><%
}
Sample code with href and onclick:
<a href='http://stackoverflow.com/' onclick='return confirm("Visit page?")'>Stackoverflow</a>
P.S. Make sure to close db connection

How to do html redirect in JSP?

I have the following JSP :
<%
String Target_Url=request.getSession().getAttribute("Target_Url").toString();
Target_Url="http://www.yahoo.com";
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
if (window.top.location != window.location)
{
window.top.location.href=window.location.href;
}
</script>
<META http-equiv="refresh" content="0;URL=${Target_Url}">
</head>
...
</html>
It's inside a frame, and should redirect to the top level location, but it's not doing that, it keeps redirect to it self, but if I hard code it like the following, it works :
<META http-equiv="refresh" content="0;URL=http://www.yahoo.com">
I guess : content="0;URL=${Target_Url}" is incorrect, what's the correct format ?
Correct format:
<META http-equiv="refresh" content="0;URL=<%=Target_Url%>">

How to insert content in a keywords metatag with JSP

I have the following JSP page:
<%#page import="com.myPath.JSPHelper"%>
<%#page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="${jspHelper.getKeywordsMetatag()}">
</head>
<body>
<%
JSPHelper jspHelper = new JSPHelper();
jspHelper.loadData(request.getAttribute("id").toString()); // load data from database
%>
<script type="text/javascript">
<%=jspHelper.getScriptContent()%>
</script>
</body>
</html>
What I'm trying to do is to fill in the contents of the keywords meta tag using a function getKeywordsMetatag() that is defined in a companion class `JSPHelper.java'.
But this is not working, I get the following error:
The function getKeywordsMetatag must be used with a prefix when a default namespace is not specified
I'm new to JSP so I've tried many things without success.
What am I doing wrong here?
What really bothers me is that the function getScriptContent() perfectly works, dumping javascript code in the html page. Why does getScriptContent() work but not getKeywordsMetatag()?
Thanks!
I would move the declaration of jspHelper up above its first use. I would also drop the ${} syntax but that might not be necessary.
<%#page import="com.myPath.JSPHelper"%>
<%#page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
JSPHelper jspHelper = new JSPHelper();
%>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="<%=jspHelper.getKeywordsMetatag()%>">
</head>
<body>
<%
jspHelper.loadData(request.getAttribute("id").toString()); // load data from database
%>
<script type="text/javascript">
<%=jspHelper.getScriptContent()%>
</script>
</body>
</html>

HTML Tag Showing in View of Rails App when Using Internet Explorer

When I view my Rails (3.1) app in Internet Explorer, for some reason it sometimes shows bits of html tags at the end of my page, but it doesn't do this in Chrome or Firefox. In particular, it shows part of the tag - never the full tag, but part - like </h or </htm - in the view as text (at the bottom of the page).
In my layout template, I do have this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><%= title %></title>
<% if params[:controller] == 'pages' %>
<%= stylesheet_link_tag "static_pages", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css" %>
<% elsif %>
<%= stylesheet_link_tag "bootstrap", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css" %>
<% end %>
<%= javascript_include_tag "https://ws.sharethis.com/button/buttons.js", "admin.js" %>
<%= csrf_meta_tag %>
<script type="text/javascript" charset="utf-8">
//jQuery.noConflict();
jQuery.extend( jQuery.fn.dataTableExt.oStdClasses, {
"sSortAsc": "header headerSortDown",
"sSortDesc": "header headerSortUp",
"sSortable": "header"
} );
jQuery(document).ready(function() {
jQuery('#datatable').dataTable( {
"sDom": "<'row'<'span5'l><'span8'f>r>t<'row'<'span4'i><'span8'p>>",
"sPaginationType": "bootstrap"
} );
} );
</script>
<%= yield :javascript%>
<%= yield :script%>
</head>
<body>
</body>
</html>
When I look at the html source code generated for the view, I notice that the Chrome/Firefox the source concludes with </body> and not </html> (or any partial code like IE).
Can someone please let me know what I'm doing wrong? Thank you.
An empty Head tag will not be recognized as well formed (closed ) unless it contains a mandatory child
( as defined in the DTD of the doctype 'Transitional' you are using. )
Give it a title
<head>
<title>A Title</title>
</head>
I think this is mandatory for all doctypes ( but don't quote me on that ) - but mute point too - every web page should have a title.
Update: Says title is present, still sounds like a "well formed" issue though ..
1) Run, view source and copy all the code into notepad/simular and save that as test.html ( this will highlight any chars that are not correct like ( " ) etc ..
2) Upload your test.html into the w3c validator service w3c Validator service
That should give some good clues
hope that cracs it

How to meta refresh after all resources were loaded?

I want to redircet to another page by meta refresh, but only after all resources were loaded. Any ideas how to archive that?
SOLUTION:
I combined both ways, the meta refresh and the jQuery way.
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%# taglib prefix="pos" uri="/WEB-INF/tld/pos.tld" %>
<%# taglib prefix="template" tagdir="/WEB-INF/tags" %>
<%# page pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="description" content="" />
<meta http-equiv="Refresh" content="1; url=${callback}/" />
<script type="text/javascript" src="/JS/pos_js/jquery-latest.js"></script>
</head>
<body>
<script>
$(document).ready(function() {
window.location = '${callback}';
});
</script>
</body>
</html>
With this way, for me, it is possible to redirect if the document in fully loaded and if JS is deactivated the meta refresh will throw the user to the callback page.
Only real way of doing it is:
<meta http-equiv="Refresh" content="1500; url=http://www.example.com/" />
That will wait 1.5 seconds for the page to load... not ideal, but without JS you'll be lucky!
edit: What about an iFramed option?
You could do this via jQuery using the $(document).load() function.
$(document).load(function() {
window.location = 'http://new.url.com';
});