Interview Questions

Java Script Auto Submit form

The following JSP file automatically submits the form values when the page is loaded in browser.


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib uri=""  prefix="c" %>

<title>Auto Login Form</title>

<script type="text/javascript">
window.onload = formSubmit;

function formSubmit() {


    <form method="post" action="<c:url value="postDataReceiverServlet"/>">
        <input type="hidden" name="username" id="username" value="admin" />
        <input type="hidden" name="password" id="password" value="admin"/>


The above file contains form values such as username and password. These values will be submitted to the action,specified in the form tag. So , when the JSP is accessed, user will be viewing the page as result of the submitted form.

This file should be placed out side WEB-INF folder,so that it can be accessed via the following URL.