Basically, I have a jsp page that when loaded will redirect the user to another URL (google.com for example). The problem I'm running into is the URL that the user is being redirected to has it's own authentication, and I'm trying to avoid the user needing to login with different credentials (I dont want to give them my UN & PW)... Is there a method or a way to hard code the username and password in the code so that it is used during the redirect?
This is what I'm doing right now:
<html>
<head>
<meta http-equiv="refresh" content="0; URL=https://www.google.com/" />
</head>
<body>
<p>Please Wait...</p>
</body>
</html>
Thanks in advance for your help!
Shawn
If the redirect is to another page of your site, store user information as you can in the session and use it on another page:
Session training
https://www.w3schools.com/php/php_sessions.asp
If you do not want to use PHP, you can send the information using the Get Address method and encode the information with one of the algorithms, but this method is not recommended !!
(I can not write good English)
The best explanation I've found for a postBack is from Wiki.
a postback is an HTTP POST to the same page that the form is on.
While the article does explain how a second page was needed in ASP, but no longer needed in ASP.NET, it doesn't give much detail or background. I am looking for a freakin' tome of information on PostBacks. Much like the simple question of "how can I clean a house" can be addressed by this 900 page book. I don't need 900 pages worth, but details please. I found a nice little tutorial for ASP.NET life cycle, but it seriously glosses over postbacks (amongst other things).
I am looking to the developers who have been around before .NET and really don't take these kinds of things for granted. Books and hyperlinks are reasonable answers or additions to your answer.
So far I've seen the right answer alluded to repeatedly, and almost everyone has come shy of what I consider subjectively to be the mark.
Let's start with the basics:
An HTTP request can be any of the HTTP verbs, but the two that people use most are GET and POST. Well, those are the two a programmer uses most frequently. The others all have some purpose, if they're implemented on the server. When you send information to the server, you can do so either through the use of the URL (to request a page) or within the body of the request (POST, PUT, DELETE, for instance).
Now you'll remark (I'm sure) that the URL in a GET request often contains data, and this is true, but according to W3C, you should not use GET to alter state, and yet we do often. It's sort of a hack that we all agree is an actual use, and not a hack. Whether that makes it a hack or an actual implementation detail I leave up to you.
So when you send the body of the POST (skipping the others for now, you can figure it out from here) with the form elements, you're sending back certain elements. How those elements are defined is up to you and to the environment you're working in. You could post to a server with a JSON element in the body, or with XML, or with form fields. Generally we do posts from a FORM element in the body of the HTML.
Now everyone says, "oh, a postback is a subsequent request to a page." But, that's not true. A postback is when you send data via POST -> back to the server. I say this because the difference between a GET request and a POST request is if data is included in the body (and the verb used, but the client usually knows how to deal with that). You could postback to the page on the first time the page is visited, and in fact ASP.NET has tools for doing that in the library. You could certainly have a desktop client POST data to a server (think Twitter) without showing any webpage at all from the server (ok, so twitter is probably not the best concept to use for an example here, but I want to illustrate that you can use a client that doesn't show the webpage, so no request is necessary).
So really what you should read there in "postback" is "I'm POSTing data BACK to the server for processing". It's presumed that you retrieved the page initially with a GET to show the user the <form> element that has <input> fields for them to interact with, and that at the end you're sending data back. But I hope you can see that it doesn't have to be in that order.
So here's something else to consider:
What if you gave the user a page with a bunch of <input>s and no <form> but instead, had a button wired up in javascript to concat all those <input>s with &value-n= and send them as a GET? Does the same thing, but violates that concept of only using GET for requests. (possibly) ensuing discussion encourages me to reinforce that GET should have no side effects (no updating values)
It's how come you can send someone a link to a google search, for instance. So we don't ALWAYS have to POST BACK to the server to get data.
Hope this helps.
Cheers
See ASP.NET Page Life Cycle Overview on MSDN for a good general introduction about what happens when a requests hits the server.
A PostBack is any request for a page that is not the first request. A PostBack will always be in response to a user action (triggered most commonly by a Button, AutoPostBack control or Ajax).
POSTBACK: Part of ASP.NET's contrived technique for hiding the true stateless nature of the web/HTTP behind a stateful facade. This results in complex code (IsPostback, ...), a hard to understand page lifecycle, many different events, ... and numerous problems (ViewState size, web-farm stickyness, state servers, browser warnings (not using PRG pattern), ...)
See ASP.NET MVC instead.
A post back is round trip from the client (Browser) to the server and then back to the client.
This enables you page to go through the asp engine on the server and any dynamic content to be updated.
here is a nice explanation
ASP.Net uses a new concept (well, new compared to asp... it's antiquated now) of ViewState to maintain the state of your asp.net controls. What does this mean? In a nutshell, if you type something into a textbox or select a dropdown from a dropdownlist, it will remember the values when you click on a button. Old asp would force you to write code to remember these values.
This is useful when if a user encounters an error. Instead of the programmer having to deal with remembering to re-populate each web control, the asp.net viewstate does this for you automatically. It's also useful because now the code behind can access the values of these controls on your asp.net web form with intellisense.
As for posting to the same page, yes, a "submit" button will post to an event handler on the code behind of the page. It's up to the event handler in the code behind to redirect to a different page if needs be (or serve up an error message to your page or whatever else you might need to do).
The Wikipedia definition of postback is pretty good, but I'd add the following:
A postback is a subsequent HTTP POST to the same page that the form is on.
If I have a page with a form on it and, rather than having my Submit button redirect the browser to another page that will process the form, instead have the Submit button refresh the current page (and perform some specific steps to validate/save the page, presumably), then that Submit button is said to have posted back to the current page.
Postbacks can be either full (refresh the entire page) or partial (in a case where AJAX is employed). A partial page postback will re-render only a part of the page (like a single drop-down list, a table, etc.).
In the old HTML, the only way to make something updated on the webpage is to resend a new webpage to the client browser. That's what ASP used to do, you have to do this thing call a "PostBack" to send an updated page to the client.
In ASP .NET, you don't have to resend the entire webpage. You can now use AJAX, or other ASP.NET controls such that you don't have to resend the entire webpage.
If you visit some old website, you would notice that once you click something, the entire page has to be refresh, this is the old ASP. In most of the modern website, you will notice your browser doesn't have to refresh the entire page, it only updates the part of the content that needs to be updated. For example, in Stackoverflow, you see the page update only the content, not the entire webpage.
Simply put this by a little code. Hope it is helpful to you.
When you firstly request the page url. you can view the source code of it in most browser. Below is a sample of it .
The essential of Post Back is actually call the __doPostBack which submit all the form data got from your firstly requested back to the server. (__EVENTTARGET contains the id of the control.)
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
NHibernate Demo
</title>
<script language="javascript" type="text/javascript">
function dopost() {
__doPostBack('LinkButton1', '');
}
</script>
</head>
<body>
<h1>NHibernate Demo</h1>
<form name="ctl01" method="post" action="Default.aspx" id="ctl01">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTMxNzcwNTYyMWRkKHoXAC3dty39nROvcj1ZHqZ5FYY=" />
</div>
<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['ctl01'];
if (!theForm) {
theForm = document.ctl01;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<div>
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="B2D7F301" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKZx5vTCgKM54rGBgLM9PumD20dn9KQguomfpAOdTG0r9Psa7al" />
</div>
<a id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')">LinkButton</a>
<input type="button" value="testPostBack" id="testpostback" onclick="dopost();" />
</form>
</body>
</html>
Postback is a request during which ASP restores values of controls' properties from view state.
Sometimes, if we post a form in page A (to page B), then we refresh the page B.
<!-- page A -->
<form action="page-b.html" method="post">
<input type="text" name="data" />
</form
Then, when we try to refresh on page B, we was prompt to confirm whether submit the POST data again.
So, I'm trying to find a way to detect whether it has some post data (or http method to be post) on page B, something may looked like:
PS: jQuery is welcome
<!-- page B -->
<script>
if(window.has_post_data()) {
// do something in case
}
</script>
There is no way to accomplish that using pure javascript or jquery. Javascript has no record of the HTTP method used to load the page. The best way to work around this issue would involve having the server add some specific variable or markup if the method was post, and search for that variable or markup using javascript.
I have been researching for that problem for many hours, and didn't find anything.
So, I have a static html page and button inside it, like that:
<body>
<button id="0">SEND EMAIL TO my#email.com</button>
</body>
And if I press this button, message "Hello" will be sent to my#email.com from my2#email.com
Is it possible to do that thing using only html or javascript or jquery (because i know only that languages)?
There are three ways to do it
Harder Way
You have to implement server code to send a mail
Less Harder Way
You have to use mailgun or sendgrid rest api to send a mail using javascript.
Simpler Way
You have to use https://formspree.io/ to send a mail from your HTML.
Update:
Recently I found a way to send email using Google script. You don't need the backend. Explained here https://github.com/dwyl/html-form-send-email-via-google-script-without-server
You can use :
<body>
<a href = 'mailto:my#email?body="Yourbody"&subject="a subject".com'>SEND EMAIL TO my#email.com</a>
</body>
It will open a mail manager (outlook, gmail, ...) to send a new mail. You can describe the body and the subject inside the link
Otherwise you can send data to PHP with a form tag and send an email this PHP.
Directly sending mail from static web page is not possible.
You can use third party service, i am using service from formspree and it is working fine for me.
All you have to do is create your account in formspree, verify gmail address and use below snippet in your HTML page.
<form action="http://formspree.io/your#email.com" method="POST">
<input type="email" name="_replyto">
<textarea name="body">
</textarea>
<input type="submit" value="Send">
</form>
formspree is self explainatory.
I'm doing some exercises trying to learn Javascript and I created a basic webform that will post form data and display the response in an iframe. ( the code is below)
I would like to add to this and store the response from the server in a variable as a string. How can this be done using plain Javascript? I understand that it would be much easier with JQuery but I want to learn the JS basics before I move onto JQuery.
Any help is appreciated.
<form action="http://BLANK.ASP" method="get" target="hiddenFrame"
<pre>
userID: <input type="text" name="userid"><br>
password: <input type="text" name="userpassword"><br>
<center>
<button type="submit">Submit</button>
</center>
</pre>
</form>
<iframe id="hiddenFrame" name="hiddenFrame" style="width:1000px">hi
</iframe>
I have a feeling you might be rubbing up against the Same Origin policy. However, if the iframe address is within the same domain, it is possible to access its contents via
document.getElementById('hiddenFrame').contentWindow.document
Then, you could grab information via .innerHTML or any other standard JavaScript method. Unfortunately, if the form processing page is not on the same domain as your webpage, you are going to run into permission errors. (see link above)
Assuming you have control over the page handling your form, you may try to pass that information to the parent page. Hopefully, your iframe is within the same domain and the above is useful to you. If you provide me with some more information about what you're doing, I can update this with some extra information.