0% found this document useful (0 votes)
62 views

GUI4 Page

The document contains code for a Java web application that allows entering PC status data into a database. Index.jsp contains the form to enter PC name, IP address, operation, and connection details. MobileServlet.java is the servlet that processes the form, checks for missing/duplicate data, inserts into the database, and displays the stored data. Missingfield.html and Duplicatedata.html contain error messages that are shown if data is missing or duplicate.

Uploaded by

Mahesh Kolhe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

GUI4 Page

The document contains code for a Java web application that allows entering PC status data into a database. Index.jsp contains the form to enter PC name, IP address, operation, and connection details. MobileServlet.java is the servlet that processes the form, checks for missing/duplicate data, inserts into the database, and displays the stored data. Missingfield.html and Duplicatedata.html contain error messages that are shown if data is missing or duplicate.

Uploaded by

Mahesh Kolhe
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Index.

jsp:
<%--
Document : index
Created on : Oct 14, 2011, 7:56:55 PM
Author : Mahesh
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body bgcolor="red" >
<form name="Mobile" action="MobileServlet1">
<br><br><h2 align="center"><b><u>PC STATUS FORM</b></u></h2><br>
<table bgcolor="cyan" align="center" border="2" width="" height="50%">
<tr> <td>Enter PC Name:</td><td><input type="text" name="pcname" value="" size="20" /></td>
</tr><tr><td>Enter IP address: </td><td><input type="text" name="ip" value="" size="20" /></td>
</tr><tr><td>Enter operation:</td> <td><input type="text" name="operation" value="" size="20"
/></td> </tr><tr><td>Enter Connection:</td><td ><input type="text" name="conn" value="" size="20"
/></td> </tr> <tr><td align="center" colspan="2"><input type="submit" value="Perform"
name="submit" /></td> </tr>
</table> </form> </body></html>

Missingfield.html:

<html> <head> <title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body> <br><br><br><br><br><br>
<font color="red" size="12">
<h2 align="center"><b><u>PLEASE FILL ALL DETAILS !!!!SOMETHING IS
MISSING!!!</u></b></h2>
</font> </body></html>

Duplicatedata.html:

<html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br><br><br><br><br><br>
<font color="red" size="12">
<h2 align="center"><b><u>ENTERED PC DATA IS ALREADY EXISTS FOR PERFORMING
OPERATION</u></b></h2> </font> </body></html>
MobileServlet.java:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package p1;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author MaheshKolhe
*/
public class MobileServlet1 extends HttpServlet {

/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
// TODO output your page here
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet MobileServlet1</title>");
out.println("</head>");
out.println("<body>");
out.println("<h2 align=center>PC INFORMATION DATA</h2>");
Class.forName("org.apache.derby.jdbc.ClientDriver");
Connection
conn=DriverManager.getConnection("jdbc:derby://localhost:1527/mak","mahesh","mahesh");

Statement st=conn.createStatement();
String pn=request.getParameter("pcname");
String ipaddr=request.getParameter("ip");
String opn=request.getParameter("operation");
String cn=request.getParameter("conn");
int temp=0;

if(pn.equals("") || ipaddr.equals("") || opn.equals("") || cn.equals(""))
{
response.sendRedirect("http://localhost:8080/MLM/MissingFieldError.html");
out.println("error ");
}

else
{
ResultSet rs1=st.executeQuery("select * from APP.PCDATA");
while(rs1.next())
{
if(rs1.getString("PCNAME").equals(pn))
{
response.sendRedirect("http://localhost:8080/MLM/DuplicateData.html");
temp=1;
break;
}
}
if(temp==0)
{

String query="insert into APP.PCDATA values('"+pn+"','"+ipaddr+"','"+opn+"','"+cn+"')";
st.execute(query);
ResultSet rs=st.executeQuery("select * from APP.PCDATA");


while(rs.next())
{
String a=rs.getString("PCNAME");
String b=rs.getString("IPADDR");
String c=rs.getString("OPERATION");
String d=rs.getString("CONN");
out.println("<table border=2 bgcolor=cyan align=center> <tr><td>PC Name</td><td>PC IP
ADDRESS</td><td>OPERATION</td><td>CONNECTION</td></tr>");
out.println("<tr><td> "+a+" </td>");
out.println("<td> "+b+" </td>");
out.println("<td> "+c+" </td>");
out.println("<td> "+d+" </td></tr></table>");

}
}

}
out.println("</body>");
out.println("</html>");




} catch (SQLException ex) {
Logger.getLogger(MobileServlet1.class.getName()).log(Level.SEVERE, null, ex);
} catch (ClassNotFoundException ex) {
Logger.getLogger(MobileServlet1.class.getName()).log(Level.SEVERE, null, ex);
} finally {
out.close();
}
}

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to
edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}

/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>

}

You might also like