Multiple Hyperlinks App
- 1. Multiple Hyperlinks App
Contains:
1. MultHyperSrv.java
2. Welcome.html
3. web.xml
Note:itis a webapp souse the codesbyformingweb-
modulesandpaste the codesthere andenjoy.
package com.nt
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.util.Date;
importjava.util.Locale;
importjavax.servlet.ServletException;
importjavax.servlet.annotation.WebServlet;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
/**
* ServletimplementationclassMultHyperSrv
*/
@WebServlet("/MultHyperSrv")
publicclassMultHyperSrvextendsHttpServlet{
private staticfinal longserialVersionUID=1L;
/**
* @see HttpServlet#HttpServlet()
*/
- 2. publicMultHyperSrv() {
super();
//TODO Auto-generatedconstructorstub
}
/**
* @see HttpServlet#doGet(HttpServletRequestrequest,HttpServletResponse response)
*/
protectedvoiddoGet(HttpServletRequestrequest,HttpServletResponse response) throws
ServletException,IOException{
//general settings
PrintWriterpw=response.getWriter();
response.setContentType("text/html");
//provide b.logic
Stringpval=request.getParameter("h1");
//forclickinghyperlink1
if(pval.equals("link1")){
String[] l=Locale.getISOCountries();
for(Stringl1:l){
pw.println(l1+"<br/>");
}
}
//forclickinghyperlink2
if(pval.equals("link2")){
String[] l1=Locale.getISOLanguages();
for(Stringl2:l1){
pw.println(l2+"<br/>");
}
}
//forclickinghyperlink3
if(pval.equals("link3")){
- 3. pw.println(new Date());
}
}
/**
* @see HttpServlet#doPost(HttpServletRequestrequest,HttpServletResponseresponse)
*/
protectedvoid doPost(HttpServletRequestrequest,HttpServletResponseresponse)throws
ServletException,IOException{
doGet(request,response);
}
}
Welcome.html codes
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>LOcale demo</title>
</head>
<body>
<div align="center">
<marquee><h1><span style=color:red>Multiple Hyperlinks
App</span></h1></marquee>
<form action="hurl" name="h1">
- 4. <a href="hurl?h1=link1">All Countries</a><br/>
<a href="hurl?h1=link2">All Languages</a><br/>
<a href="hurl?h1=link3">Date & Time</a>
</div>
</body>
</form>
</html>
web.xml codes
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">
<display-name>MultipleHyperlinksApp</display-name>
<welcome-file-list>
<welcome-file>Welcome.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>hyper</servlet-name>
<servlet-class>com.nt.MultHyperSrv</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hyper</servlet-name>
<url-pattern>/hurl</url-pattern>