SlideShare a Scribd company logo
Multiple Submit Button Test App
Contains:
1. SubmitSrv.java
2. Index.html
3. web.xml
note: it is a web app so use the codes by forming web-modules and
paste the codes there and enjoy.
1. SubmitSrv.java codes
package com.nt;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.util.Date;
importjava.util.Properties;
importjavax.servlet.ServletException;
importjavax.servlet.annotation.WebServlet;
importjavax.servlet.http.HttpServlet;
importjavax.servlet.http.HttpServletRequest;
importjavax.servlet.http.HttpServletResponse;
/**
* ServletimplementationclassSubmitSrv
*/
@WebServlet("/SubmitSrv")
publicclassSubmitSrvextendsHttpServlet{
private staticfinal longserialVersionUID=1L;
/**
* Defaultconstructor.
*/
publicSubmitSrv() {
//TODO Auto-generatedconstructorstub
}
/**
* @see HttpServlet#doGet(HttpServletRequestrequest,HttpServletResponse response)
*/
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponse response) throws
ServletException,IOException{
//general setings
PrintWriterpw=response.getWriter();
response.setContentType("text/html");
//requestprocessinglogicfordifferentoperations
Stringpval=request.getParameter("s1");
//logicforseparate submit execution
if(pval.equals("ADD")){
intval1=Integer.parseInt(request.getParameter("t1"));
intval2=Integer.parseInt(request.getParameter("t2"));
pw.println("Additionis:"+(val1+val2));
}
else if(pval.equals("SUB")){
intval1=Integer.parseInt(request.getParameter("t1"));
intval2=Integer.parseInt(request.getParameter("t2"));
pw.println("Additionis:"+(val1-val2));
}
else if(pval.equals("MUL")){
intval1=Integer.parseInt(request.getParameter("t1"));
intval2=Integer.parseInt(request.getParameter("t2"));
pw.println("Additionis:"+(val1*val2));
}
else if(pval.equals("link1")){
pw.println(System.getProperties());
}
else{
pw.println(newDate());
}
//close stream
pw.close();
}
/**
* @see HttpServlet#doPost(HttpServletRequestrequest,HttpServletResponseresponse)
*/
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throws
ServletException,IOException{
doGet(request,response);
}
}
Index.html codes
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="surl">
<div align="center">
<table>
<tr>
<td>Value 1: <input type="text" name="t1"><br></br>
Value 2: <input type="text" name="t2"><br></br></td>
</tr>
<tr align="center">
<td>
<input type="submit" name="s1" value="ADD">
<input type="submit" name="s1" value="SUB">
<input type="submit" name="s1" value="MUL">
</td>
</tr>
<tr>
<td><a href="surl?s1=link1">System
Properties</a>&nbsp;&nbsp;&nbsp;
<a href="surl?s1=link2">System Date</a>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Web.xml codes
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns:web="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_2_5.xsd">
<display-name>MultipleSubmitBtnTestApp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>testapp</servlet-name>
<servlet-class>com.nt.SubmitSrv</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>testapp</servlet-name>
<url-pattern>/surl</url-pattern>
</servlet-mapping>
</web-app>

More Related Content

DOCX
Online Form Submission App
DOCX
Servlet LifeCycle Demo App
PPT
Testing Ajax Web Applications
DOCX
How to use_cucumber_rest-assured_api_framework
PPTX
Ng2 cli
PPTX
Selenium webcrawler
PDF
Data Flow Patterns in Angular 2 - Sebastian Müller
PDF
Uploading files using selenium web driver
Online Form Submission App
Servlet LifeCycle Demo App
Testing Ajax Web Applications
How to use_cucumber_rest-assured_api_framework
Ng2 cli
Selenium webcrawler
Data Flow Patterns in Angular 2 - Sebastian Müller
Uploading files using selenium web driver

What's hot (19)

PDF
Designing an effective hybrid apps automation framework
PDF
Selenium RC - Web Application Testing Tool
PDF
Akmal Khaleeq Waheed - Challenge 3 p3
PPTX
Reactive application using meteor
DOCX
Spring diy projects
PPTX
MuleSoft ESB Testing Mule Application using MUnit Test Suite
PDF
Selenium Overview
PDF
Introduction to Automation Testing and Selenium overiew
PPTX
QSpiders - Selenium Webdriver
PPTX
Selenium Webdriver
PPT
Selenium
PPTX
Automation Testing by Selenium Web Driver
PPTX
Cucumber with appium
PPTX
How to configure Appium with android IDE & eclipse
PPTX
Force.com Migration Tool
PPT
Web Test Automation with Selenium
PPT
QSpiders - Automation using Selenium
PPTX
How to Configure Selenium WebDriver (java)
PDF
Mobile Testing with Selenium 2 by Jason Huggins
Designing an effective hybrid apps automation framework
Selenium RC - Web Application Testing Tool
Akmal Khaleeq Waheed - Challenge 3 p3
Reactive application using meteor
Spring diy projects
MuleSoft ESB Testing Mule Application using MUnit Test Suite
Selenium Overview
Introduction to Automation Testing and Selenium overiew
QSpiders - Selenium Webdriver
Selenium Webdriver
Selenium
Automation Testing by Selenium Web Driver
Cucumber with appium
How to configure Appium with android IDE & eclipse
Force.com Migration Tool
Web Test Automation with Selenium
QSpiders - Automation using Selenium
How to Configure Selenium WebDriver (java)
Mobile Testing with Selenium 2 by Jason Huggins
Ad

More from Peeyush Ranjan (10)

DOCX
Multiple Hyperlinks App
DOCX
Photo Insert and Retrieve App
DOCX
Scrollable Test App
DOCX
Scrollable Demo App
DOCX
Cursor Demo App
DOCX
Batch processing Demo
DOCX
Transaction Management Tool
DOCX
Net Beans Codes for Student Portal
DOCX
TextSearch
DOCX
Multiple Hyperlinks App
Photo Insert and Retrieve App
Scrollable Test App
Scrollable Demo App
Cursor Demo App
Batch processing Demo
Transaction Management Tool
Net Beans Codes for Student Portal
TextSearch
Ad

Multiple Submit Button Test App

  • 1. Multiple Submit Button Test App Contains: 1. SubmitSrv.java 2. Index.html 3. web.xml note: it is a web app so use the codes by forming web-modules and paste the codes there and enjoy. 1. SubmitSrv.java codes package com.nt; importjava.io.IOException; importjava.io.PrintWriter; importjava.util.Date; importjava.util.Properties; importjavax.servlet.ServletException; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; importjavax.servlet.http.HttpServletRequest; importjavax.servlet.http.HttpServletResponse; /** * ServletimplementationclassSubmitSrv */ @WebServlet("/SubmitSrv") publicclassSubmitSrvextendsHttpServlet{ private staticfinal longserialVersionUID=1L; /**
  • 2. * Defaultconstructor. */ publicSubmitSrv() { //TODO Auto-generatedconstructorstub } /** * @see HttpServlet#doGet(HttpServletRequestrequest,HttpServletResponse response) */ publicvoiddoGet(HttpServletRequestrequest,HttpServletResponse response) throws ServletException,IOException{ //general setings PrintWriterpw=response.getWriter(); response.setContentType("text/html"); //requestprocessinglogicfordifferentoperations Stringpval=request.getParameter("s1"); //logicforseparate submit execution if(pval.equals("ADD")){ intval1=Integer.parseInt(request.getParameter("t1")); intval2=Integer.parseInt(request.getParameter("t2")); pw.println("Additionis:"+(val1+val2)); } else if(pval.equals("SUB")){ intval1=Integer.parseInt(request.getParameter("t1")); intval2=Integer.parseInt(request.getParameter("t2")); pw.println("Additionis:"+(val1-val2)); } else if(pval.equals("MUL")){ intval1=Integer.parseInt(request.getParameter("t1")); intval2=Integer.parseInt(request.getParameter("t2")); pw.println("Additionis:"+(val1*val2));
  • 3. } else if(pval.equals("link1")){ pw.println(System.getProperties()); } else{ pw.println(newDate()); } //close stream pw.close(); } /** * @see HttpServlet#doPost(HttpServletRequestrequest,HttpServletResponseresponse) */ publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throws ServletException,IOException{ doGet(request,response); } } Index.html codes <!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> </head>
  • 4. <body> <form action="surl"> <div align="center"> <table> <tr> <td>Value 1: <input type="text" name="t1"><br></br> Value 2: <input type="text" name="t2"><br></br></td> </tr> <tr align="center"> <td> <input type="submit" name="s1" value="ADD"> <input type="submit" name="s1" value="SUB"> <input type="submit" name="s1" value="MUL"> </td> </tr> <tr> <td><a href="surl?s1=link1">System Properties</a>&nbsp;&nbsp;&nbsp; <a href="surl?s1=link2">System Date</a> </td> </tr> </table> </div> </form>
  • 5. </body> </html> Web.xml codes <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns:web="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_2_5.xsd"> <display-name>MultipleSubmitBtnTestApp</display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> <servlet> <servlet-name>testapp</servlet-name> <servlet-class>com.nt.SubmitSrv</servlet-class> </servlet> <servlet-mapping> <servlet-name>testapp</servlet-name> <url-pattern>/surl</url-pattern> </servlet-mapping> </web-app>