Glassfish how to prevent direct access to a html file - html

I am running glassfish 3.1
Say I have 2 html files: a.html b.html and their urls are:
http://localhost:8080/mysite/a.html
http://localhost:8080/mysite/b.html
I only want a user to click a link from within a.html to get to b.html. if a user try to directly access b.html using http://localhost:8080/mysite/b.html, he should be redirected back to a.html.
How do i achieve this? I read something about .htaccess file. Does glassfish support this where should I find this file and modify it to suit my needs as stated above?

when user clicks link on a.html to go to b.html, save a flag in database(using javascript for click -> database for save ). On loading b.html, first check the flag(database for retrieval -> javascript to check), if untrue, go back to a.html, else show b.html.

Depending on how your users would move from page a to b. What you could do is instead of clicking a link going to page-b have a button.
Then that button can be part of a form with a hidden value... and check on page-b if that value was posted if not then redirect to page-a for example.
page-a:
<form action="b.php" method="post">
<input type="submit" name="a_submit" value="Go to page b">
</form>
top of page-b:
<?php
if(isset($_POST['a_submit'])){
///they came from page a
}else{
header('Location:a.html');
}
?>
With these two pieces of code you can implement exactly what you wanted. The only catch is you have to rename your b.html to b.php this is because only php files can handle php scripts. But do not worry there is no down side of using a php file instead of html; they act exactly the same but they only also allow php scripts to be ran.

Related

What happens when submitting an html form? (the process behind the scenes)

Can someone please tell me what happens behind the scenes in the following case (i.e. explain the whole technical process)?
<form method="get" action="#">
<input type="text" name="d" value="flowers">
<button type="submit">send</button>
</form>
In this case after one has clicks on “send” a new webpage opens saying: "You have searched for "flowers" " and an image of some flowers below.
In the browser tab right after the URL of the newly opened page there is
“/?s=flowers”. What is that?
Thank you in advance for your answers!
When you click Send, the page data specified in the form information and values is passed to the server via HTTP.
The /?s=flowers is the GET data being passed back to the server. Although, based on the form code you've provided, the "name" of that value is d. So the URL would actually have /?d=flowers
The PHP or server side language then handles that information to do specific tasks. It can access the info using the name "d". This method of sending data is called GET, there are also other ways of doing this. The most common, POST, does not display the data in the URL and send the data through HTTP headers.
The code you've shown has an action of "#" which means the HTTP method is being sent the same page. Meaning this page code would have some PHP located in it. This can also be done by using a seperate file, such as action='send.php'

Grails Project - Open dialog box

In my application, when I hit Run button which is scripted in gsp page as:
<input type="button" value="Run" onClick="submitJob()"></input>
submitJob() function is defined in a ExtJs JavaScript file which does some operations and calls the controller code which renders a different gsp output page as:
render(template: "/plugin/jobPlot_out", model:[jobName:jobName], contextPath:pluginContextPath)
In my application in web browser it displays the output in the same web page. How to display the same output in a dialog box and not in the same page?
I am new to JavaScript so I posted this question. What I did:
I had to search for the div id of the Run button and had to search for the URL where the div id gets loaded. Upon finding this, I had to write a jQUERY code to open a dialog box and the resulting output was rendered there.
I'm not pretty sure I got you right but have you tried to use a redirect instruction?
http://grails.github.io/grails-doc/3.0.x/ref/Controllers/redirect.html

form action="your-shop" : what does this mean without file extension?

I have seen filename(with file extension) or URL inside action attribute but never seen anything like this code below.
<form action="your-shop" name="shop_name_form" id="shop_name_form" method="post" onsubmit="return check_shopname(this);">
</form>
Here action attribute contains may be a file name but no file name extension.
What will it do when i press submit button?please explain it in details
It's a relative URL and will be resolved against the current URL. E.g. If the page is located at http://example.com/current/path/foo, the from will be submitted to http://example.com/current/path/your-shop.
File extensions have no meaning in a URL, how the path is processed depends on the server implementation.
At first it calls the Javascript function check_shopname();.
If it returns false, the submit will be canceled, so maybe there is no case where true is returned, because the Admin handles all the things on the client side!
The second possibility is, that the url of the sites are modified by mod_rewrite, and you get redirected to another file, for example, by adding a .html or .php extension.
If you will take you to the following link for form submission.
www.yourwebsite.com/your-shop. your-shop will be appeneded to the website's URL. Since there is no folder or other directory included. As Felix has mentioned already in comments, the File extension like .html has no meaning here in this context of action.

Server Side Includes with variable (IIS 7)

I am trying to build a universal header file that I can include in each .html file on my site. My header contains several dropdown tabs, and one of the tabs is always highlighted (depending on which page the user is on). So I want to do something like a server side include for the header, but I also want to give it a variable so that it knows which tab to highlight, something like this:
<div class="topmenu">
<ul>
<someScript>
if (variable=="home") {
print "<li class='current'>";
} else {
print "<li>";
}
</someScript>
...
My server is IIS 7 and doesn't support PHP, and I don't want to rename all my files to *.asp so that I can use ASP. How could I go about this?
By the extension I guess you would use Classic ASP. Then something like this should work:
<!--#include file="header.asp"-->
You can put this in each file you want to have a header.
Of couse, you should create that "header.asp" page first ;)
For highligthing the tab of the page you're in, there're several methods.
IMHO, I suggest a clientside script to do that. JS or jQuery of course.
You could check the file name of the URL you are in and give the proper class to the tab so it will be highligthed.
Example ( jQuery needed ):
var currentPage = window.location.pathname.substring(url.lastIndexOf('/')+1);
if(currentPage == 'default.asp') $('li.homepage a').addClass('current');
This simple code retrives the file name and, by it, add a class to the corresponding element in your navigation.
Of course this is a conceptual script, you'd better adapt it to your page.

Need jsp form to submit query to specific path

I'm trying to setup a simple form in a jsp that will put a search query in the URL submitted.
This is what I have so far:
<form action="search/" method="get" onsubmit="this.action+=this.q.value.trim();return true">
<input type="text" id="q">
<input type="submit" value="go">
</form>
This is in a jsp that's included on each page of my web app and it works when I'm at the root of the app. For example, if I initially load "http://localhost:8080/MyApp/" then type "123456" in the search form, it takes me to "http://localhost:8080/MyApp/search/123456", which is what I want. However, from that page, if I search again (for "654321" for example) it goes to "http://localhost:8080/MyApp/search/search/654321", which doesn't work for me. I need search/{query} to be appended to the root of the app's path no matter what page I may be on at the time.
I would like to avoid javascript if possible, I'm fine with JSTL though.
Any suggestions would be much appreciated!
Simply add a full path to your action, start it with /. Note it will depend on your application context, you could use :
<form action="${pageContext.request.contextPath}/search/"...
It will work in dev and also prod.
EDIT :
Path : search will try to load relative from current path so : http://domain.com/contact/search/
Path : /search will try to load relative from the domain so : http://domain.com/
With the context path above, it will work no matter if it change from dev to prod.
Hope this helps!