answersLogoWhite

0

JSP and Servlets

JSP (JavaServer Pages) are Java programs encoded within webpages that research and generate pertinent results. Servlets, on the other hand, are objects (programs) that handle requests from users and provide results based on these requests.

500 Questions

How do you retrieve table data from mysql to jsp?

User Avatar

Asked by Wiki User

<%@ page import ="java.sql.*" %>

<%@ page import ="javax.sql.*" %>

<%@ page import ="java.io.*" %>

<%@ page language="java" import="java.util.*,java.text.SimpleDateFormat;" pageEncoding="ISO-8859-1"%>

<html>

<%

Calendar currentDate = Calendar.getInstance();

SimpleDateFormat formatter= new SimpleDateFormat("dd/MM/yyyy");

String dateNow = formatter.format(currentDate.getTime());

String nam=(String)request.getAttribute("uname");

String pwd=(String)request.getAttribute("pwd");

request.setAttribute("date",dateNow);

request.setAttribute("nam",nam);

request.setAttribute("pwd",pwd);

System.out.print(nam);

%>

<%

String full_name=request.getParameter("fname");

String cn=request.getParameter("name");

String deg=request.getParameter("designation");

String ema=request.getParameter("email");

String mobile=request.getParameter("mob_no");

String serial=request.getParameter("ser_no");

String department=request.getParameter("deptt_name");

String off_add=request.getParameter("office_address");

String st_name=request.getParameter("state_name");

String spin=request.getParameter("pin");

String phn_no=request.getParameter("phone_no");

String svar1=request.getParameter("srvip");

String svar2=request.getParameter("srvloc");

String svar3=request.getParameter("destport");

String svar4=request.getParameter("descrsrv");

String placen=request.getParameter("place");

String vdate=request.getParameter("date");

String rname=request.getParameter("r_name");

String rdesg=request.getParameter("r_designation");

String remail=request.getParameter("r_email");

String rphone=request.getParameter("r_phone");

String cname=request.getParameter("c_name");

String cdesg=request.getParameter("c_designation");

String cemail=request.getParameter("c_email");

String cphone=request.getParameter("c_phone");

String issby=request.getParameter("captchatext");

Class.forName("com.mysql.jdbc.Driver");

Connection con = DriverManager.getConnection("jdbc:mysql://localhost/vpn","root","test123");

Statement st= con.createStatement();

int i=st.executeUpdate("insert into vpn_registration(cname,name,designation,email,mobile,serial_no,name_dept,off_add,state,pincode,off_phone,place,rname,rdesign,rmail,rmob,c_name,cdesign,cmail,cmob,issuedby) values ('"+cn+"','"+full_name+"','"+deg+"','"+ema+"','"+mobile+"','"+serial+"','"+department+"','"+off_add+"','"+st_name+"','"+spin+"','"+phn_no+"','"+placen+"','"+rname+"','"+rdesg+"','"+remail+"','"+rphone+"','"+cname+"','"+cdesg+"','"+cemail+"','"+cphone+"','"+issby+"')");

Statement st1= con.createStatement();

int y=st1.executeUpdate("insert into server_details(registration_no,serip,serloc,destport,desc_service) values ('"+svar1+"','"+svar2+"','"+svar3+"','"+svar4+"')");

st.close();

con.close();

%>

<head>

<title>ONLINE VPN REGISTRATION FORM</title>

<style>

a, A:link, a:visited, a:active

{color: #0000aa; text-decoration: none; font-family: Tahoma, Verdana; font-size: 11px}

A:hover

{color: #ff0000; text-decoration: none; font-family: Tahoma, Verdana; font-size: 11px}

p, tr, td, ul, li

{color: #000000; font-family: Tahoma, Verdana; font-size: 11px}

.header1, h1

{color: #ffffff; background: #4682B4; font-weight: bold; font-family: Tahoma, Verdana; font-size: 13px; margin: 0px; padding-left: 2px; height: 21px}

.ctrl

{font-family: Tahoma, Verdana, sans-serif; font-size: 12px; width: 100%;}

.btnform

{border: 0px; font-family: tahoma, verdana; font-size: 12px; background-color: #DBEAF5; width: 100%; height:18px; text-align: center; cursor: hand;}

.btn

{background-color: #DBEAF5; padding: 0px;}

textarea, select,input

{font: 9px Verdana, arial, helvetica, sans-serif; background-color: #DBEAF5;}

</style>

<SCRIPT language="javascript">

function addRow(tableID) {

var table = document.getElementById(tableID);

var rowCount = table.rows.length;

if(rowCount>6)

{

alert("Cannot add more than 6 rows.");

return false;

}

document.getElementById("rowlength").value=rowCount;

var row = table.insertRow(rowCount);

var counts=rowCount-1;

var cell0 = row.insertCell(0);

var chk = document.createElement("input");

chk.type = "checkbox";

chk.name="chk"+counts+"";

cell0.appendChild(chk);

var cell1 = row.insertCell(1);

var srvip = document.createElement("input");

srvip.name="srvip"+counts+"";

srvip.id="srvip"+counts+"";

srvip.className='ctrl';

srvip.type = "text";

//srvip.onClick="hello()";

cell1.appendChild(srvip);

var cell2 = row.insertCell(2);

var srvloc = document.createElement("input");

srvloc.type = "text";

srvloc.className='ctrl';

srvloc.name="srvloc"+counts+"";

cell2.appendChild(srvloc);

var cell3 = row.insertCell(3);

var destport = document.createElement("input");

destport.type = "text";

destport.className='ctrl';

destport.name="destport"+counts+"";

destport.id="destport"+counts+"";

cell3.appendChild(destport);

var cell4 = row.insertCell(4);

var descrsrv = document.createElement("input");

descrsrv.type = "text";

descrsrv.className='ctrl';

descrsrv.name="descrsrv"+counts+"";

cell4.appendChild(descrsrv);

}

</SCRIPT>

<script type="text/javascript">

function clearFields()

{

document.cmaForm.reset();

}

</script>

<SCRIPT language="javascript">

function deleteRow(tableID) {

try {

var table = document.getElementById(tableID);

var rowCount = table.rows.length;

for(var i=0; i<rowCount; i++) {

var row = table.rows[i];

var chkbox = row.cells[0].childNodes[0];

if(null != chkbox && true == chkbox.checked) {

if(rowCount <= 2) {

alert("Cannot delete all the rows.");

break;

}

table.deleteRow(i);

rowCount--;

i--;

}

}

}catch(e) {

alert(e);

}

}

</SCRIPT>

<script type="text/javascript">

function setid()

{

var x=document.cmaForm.rowlength.value;

//alert(x);

document.cmaForm.id=x;

return true;

}

</script>

<script type="text/javascript" src="vpn.js"></script>

</head>

<body onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="noBack();" bgcolor="white">

<!-- Header -->

<table cellpadding="0" cellspacing="0" width="100%" border="0" bgcolor="#ffffff">

<tr>

<td align="center"><img src="img/nic.jpg" width="65%" height="80" border="0" alt="NIC Logo"></td>

</tr>

<tr><td><img src="img/line9.gif" width="1" height="5" border="0"></td></tr>

</table>

<!-- Form -->

<form method="post" name="cmaForm" action="vpn_registration.jsp" id="0" onSubmit="return setid(),validate_form(this.id)" >

<table cellpadding="0" cellspacing="0" border="0" width="65%" align="center">

<tr>

<td bgcolor="#4682B4" width="10"><img src="img/line9.gif" width="10" height="1" border="0"></td>

<td class="header1" nowrap>NIC VPN Services<img src="img/line9.gif" width="10" height="1" border="0"></td>

<td><img src="img/line5.gif" width="10" height="21" border="0"></td>

<td background="img/line8.gif" width="100%">&nbsp;</td>

<td background="img/line8.gif"><img src="img/line9.gif" width="10" height="1" border="0"></td>

</tr>

<tr>

<td background="img/line6.gif"><img src="img/line9.gif" border="0"></td>

<td colspan="3"><img src="img/line9.gif" width="1" height="10" border="0"><br>

<table cellpadding="0" cellspacing="0" border="0" width="100%">

<tr><td bgcolor="#DBEAF5">

<table cellspacing="1" cellpadding="2" border="0" width="100%">

<tr bgcolor="#ffffff">

<td colspan="7" align="center"><font size="2">National Infomatics Centre <br> Department of Information Technology<br>Ministry of Communications and Information Technology

<br> Government of India</font></td>

</tr>

<tr bgcolor="#4682B4">

<td colspan="7" align="center"><font size="2" color="white"><b>VPN Registration Form</b></font></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7"><b>Note:</b>&nbsp;&nbsp;Fields marked<font size="2" color="red"> * </font>are mandatory.

</td>

</tr>

<logic:present name="fail">

<tr><td colspan=7 align="center" ><font color="red" size="5">${fail}</font></td></tr>

</logic:present>

<tr bgcolor="#ffffff">

<td colspan="7" align="center"><b>SECTION I : SUBSCRIBER INFORMATION</b></td>

</tr>

<tr bgcolor="#CCCCCC">

<td colspan="7">&nbsp;1.1 Personal Details:</td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;Full Name:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="fname" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;Common Name:</td>

<td colspan="5" width="50%"><input type="text" name="name" value="<%= request.getParameter("uname")%>" readonly="readonly"class="ctrl"></td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;Designation:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="designation" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;E-mail Address:<font size="2" color="red">* </font></td>

<td colspan="5" width="50%"><input type="text" name="email" class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;Mobile:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="mob_no" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;DC Serial No.:</td>

<td colspan="5" width="50%"><input type="text" name="ser_no" value="<%= request.getParameter("pwd")%>" readonly="readonly"class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#CCCCCC">

<td colspan="7">&nbsp;1.2 Official Address:</td>

</tr>

<tr bgcolor="#ffffff">

<td>&nbsp;Name of the Department:<font size="2" color="red">* </font></td>

<td bgcolor="#ffffff" colspan="7"><input type="text" name="deptt_name" size="35" class="ctrl"></td>

</tr>

<tr bgcolor="#ffffff">

<td >&nbsp;Office Address:<font size="2" color="red">* </font></td>

<td colspan="7"><input type="text" name="office_address" size="35" class="ctrl"></td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;State:</td>

<td colspan="1" width="35%"><input type="text" name="state_name" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;Pin Code:<font size="2" color="red">* </font></td>

<td colspan="5" width="50%"><input type="text" name="pin" class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%" >&nbsp;Office Telephone:</td>

<td colspan="1" width="35%"><input type="text" name="phone_no" size="35" class="ctrl"></td>

<td colspan="6" width="5%"></td>

</tr>

<tr bgcolor="#CCCCCC">

<td colspan="7">&nbsp;1.3 List of Server to access through VPN:<font size="2" color="red">* </font></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7">

<TABLE border="1" class="ctrl" id="addressesTable">

<TR>

<td width="21">&nbsp;</td>

<TD width="150">IP Address of the Server</TD>

<TD width="196">Location of the Server</TD>

<TD width="167">Destination Port</TD>

<TD width="162">Website/URL of Servers</TD>

</TR>

<TR>

<TD>

<INPUT name="chk" type="checkbox" class="ctrl" disabled="disabled"/></TD>

<TD><INPUT name="srvip0" type="text" id="srvip0" class="ctrl" /></TD>

<TD><input name="srvloc0" type="text" class="ctrl" value=""></TD>

<TD><INPUT name="destport0" type="text" id="destport0"class="ctrl" /></TD>

<TD><INPUT name="descrsrv0" type="text" class="ctrl" />

<input type="hidden" name="rowlength" id="rowlength" value="1">

</TD>

</TR>

</TABLE>

</td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7" align="left"><input name="des_ser2" value="Add New" type="button" onClick="addRow('addressesTable')" />

<INPUT type="button" value="Delete" onClick="deleteRow('addressesTable')" /></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7" align="center"><font size="2"><u>DECLARATION</u></font></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7">I hereby declare that<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1. The information provided is correct.<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2. Is responsible for the safety of the Digital Certificate, PIN, Username and Password issued for accessing VPN Service.<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;3. I undertake to surrender the VPN account and Digital certificate on transfer / leaving the division.<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;4. The certificate and VPN account are issued will be used only for accessing the NIC VPN Service as per the list provided in 1.3.<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;5. Will not indulge in any activity and no attempt will be made to gain unauthorized access to other NIC Websites and facilities.<br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6. I am responsible for the content/ data uploaded in the servers through VPN connection.<br>

&nbsp;I have read the terms and conditions of NIC VPN Services and will comply with. If at a later stage any information is found to be incorrect or non-compliance with the terms and conditions will result in the cancellation of the DC issued by NIC for NIC VPN service.</td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;Place:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="place" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;Date:</td>

<td colspan="5" width="50%"><input type="text" name="date" value="${date}" readonly="readonly" class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7" align="center"><b>SECTION II : RECOMMENDATION</b></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7">&nbsp;This is to certify that the person as identified in SECTION-I has provided correct information and is authorized on behalf of the organization to update and access servers listed in 1.3.<br>

&nbsp;I shall intimate NIC VPN Division to deactivate the account when the person is transferred / relived from responsibility for which the VPN account and digital certificate is issued.

</td>

</tr>

<tr bgcolor="#CCCCCC">

<td colspan="7">&nbsp;2.1 Verification by Recommending/Reporting/Head of Office</td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;Name:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="r_name" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;Designation:<font size="2" color="red">* </font></td>

<td colspan="5" width="50%"><input type="text" name="r_designation" class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;E-mail Address:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="r_email" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;Contact No.:<font size="2" color="red">* </font></td>

<td colspan="5" width="50%"><input type="text" name="r_phone" class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7" align="center"><b>SECTION III : Verification by NIC-Coordinator</b></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7" align="left" ><a href="http://webservices.nic.in/webcoord.aspx" target="blank"> <u> &nbsp;Please refer the authorised NIC Web Co-ordinator</a></u></td>

</tr>

<tr bgcolor="#ffffff">

<td colspan="7">&nbsp;User Category: Free / Paid<br>

&nbsp;If free enclose the copy of the approval.<br>

&nbsp;If paid, then confirm the period for which payment is made: From:.................To:.................<br>

&nbsp;Project No. ......................................................................................................................<br>

&nbsp;The web sites mentioned at 1.3 (a) in SECTION-I am correct. The subscriber is the authorized person to update this web site and require VPN Services. Permission may give for the same.<br>

&nbsp;I shall intimate NIC VPN division to deactivate the account when the person is transferred / relived from responsibility for which the VPN account and digital certificate is issued.

</td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;Name:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="c_name" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;Designation:<font size="2" color="red">* </font></td>

<td colspan="5" width="50%"><input type="text" name="c_designation" class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;E-mail Address:<font size="2" color="red">* </font></td>

<td colspan="1" width="35%"><input type="text" name="c_email" size="12" class="ctrl"></td>

<td colspan="1" width="5%">&nbsp;Contact No.:<font size="2" color="red">* </font></td>

<td colspan="5" width="50%"><input type="text" name="c_phone" class="ctrl" size="10"></td>

</tr>

<tr bgcolor="#ffffff">

<td width="15%">&nbsp;Enter the Letters:<font size="2" color="red">* </font></td>

<td colspan="1" width="20%"><input type="text" name="captchatext" size="12" class="ctrl"></td>

<td colspan="1" width="20%">&quot;</td>

<td colspan="1" width="20%"><input type="image" name="captchaimg" src="/vpn_app/jcaptcha" size="12" class="ctrl"></td>

<td colspan="4" width="25%"></td>

</tr>

</table></td></tr></table>

<img src="img/line9.gif" width="1" height="10" border="0"><br>

</td>

<td background="img/line7.gif"><img src="img/line9.gif" border="0"></td>

</tr>

<tr>

<td width="10"><img src="img/line4.gif" width="10" height="20" border="0"></td>

<td bgcolor="#4682B4" colspan="4" align="right">

<table cellpadding="0" cellspacing="0" border="0">

<tr>

<td class="btn" width="100"><input type="submit" name="Submit" value="Submit" class="btnform"></td>

<td width="1"><img src="img/line9.gif" width="1" height="18" border="0"></td>

<td class="btn" width="100"><input type="reset" name="Reset" value="Reset" class="btnform"></td>

<td width="1"><img src="img/line9.gif" width="1" height="18" border="0"></td>

</tr>

</table>

</td>

</tr>

</table>

</form>

<!-- Footer -->

<table align="center" cellpadding="3" cellspacing="0" width="65%" border="0" height="22">

<tr bgcolor="#DBEAF5">

<td align="center"><font face="Tahoma">For any query please contact VPN Support:</font><font color="blue" face="Tahoma">vpnsupport[at]nic[dot]in</font>

<br>

<font face="Tahoma">Contact No:</font> <font color="blue" face="Tahoma">+91-11-24305391 / 99</font></td>

</tr>

<logic:present name="fail">

${fail}

</logic:present>

</table>

<!-- /Footer -->

</body>

</html>

How do you get the image file from the database with JSP?

User Avatar

Asked by Wiki User

You can retrieve an image file from a database in JSP by writing a servlet that fetches the image from the database and streams it to the JSP page. The servlet will set the content type to "image/jpeg" or the appropriate image format and write the image data to the response output stream. In the JSP page, you can then display the image by setting the source attribute of the img tag to the servlet URL.

What is j2ee and jsp?

User Avatar

Asked by Wiki User

Is the JSP tutorial easy to follow and understand?

User Avatar

Asked by Wiki User

Yes, the JSP tutorial is easy to follow and understand. It tells you what it is doing from start to finish. When the JSP life cycle is complete a screen will pop up and they are finished.

What is javax servlet?

User Avatar

Asked by Wiki User

A Servlet is a Java programming language class used to extend the capabilities of a server. Although servlets can respond to any types of requests, they are commonly used to extend the applications hosted by web servers

A Servlet is a Java-based server-side web technology.

The javax.servlet package contains a number of classes and interfaces that describe and define the contracts between a servlet class and the runtime environment provided for an instance of such a class by a conforming servlet container.

How many page directive can use in a single JSP?

User Avatar

Asked by Wiki User

There is no limit as such. You can use one or more Page Directives in a JSP but you cannot have duplicates

Why you use java server pages?

User Avatar

Asked by Wiki User

it's provide dynamically facility to web pages...

How you can display servlet page in jsp page?

User Avatar

Asked by Wiki User

You cannot. You display JSP Pages using the help of Servlets. Servlets are of the background classes and you cannot display them

Which method must to override in Servlet?

User Avatar

Asked by Wiki User

There are 3 main types of requests that get processed by a Servlet. They are:

• Get

• Post

• Put

Each of them have a corresponding doXXX() method in the Servlet class which would be:

• doGet

• doPost

• doPut

You must override either of these methods based on the type of requests that would be processed by your servlet

Is Servlet instance Thread safe If not how can you make thread safe?

User Avatar

Asked by Wiki User

No. The Servlet is not thread-safe by default. You can make it thread safe by implementing the SingleThreadedModel interface