# 4
i am developing an application that have a jsp page like this
<%@ page language="java"%>
<%@ page import="com.bss.bean.SessionUserInfo" %>
<%@ page import="java.util.Vector"%>
<%@ page import="com.bss.bean.Device" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<html:html locale="true">
<head>
<title>BSS - Device Status Settings</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<!--<link rel="stylesheet" type="text/css" href="styles.css">-->
<STYLE type="text/CSS">
<!--
TD.HEADING {bgcolor:#ACBBCC ;font-family:Arial;
font-size:12pt; font-style:bold; text-indent:3ex }
TD.NORMAL {font-family:Arial; font-size:11pt ; text-indent:5ex }
TR.NORMAL {font-family:Arial; font-size:12pt ; text-indent:3ex; align:center }
TD.FOOTER {font-family:Arial; font-size:10pt }
-->
</STYLE>
</head>
<jsp:useBean id="htmlUtil" class="com.bss.utilities.HtmlUtil" scope="session"></jsp:useBean>
<body bgcolor="#ACBCCC">
<table height="100%" width = "100%" border=0 >
<tr height="20%">
<td>
<%=htmlUtil.getHeader((SessionUserInfo)session.getAttribute(SessionUserInfo.class.getName()))%>
</td>
</tr>
<tr ><td height="70%">
<table width=100% height = "100%" border="1" align="center">
<tr>
<td width=70%>
<form action="SetNewStatus" method="POST">
<% Vector devices = (Vector)session.getAttribute("devices");
String names[] = new String[8];
String status[] = new String[8];
for(int i = 0; i< devices.size(); i++){
names = ((Device)devices.elementAt(i)).getDevice();
status = ((Device)devices.elementAt(i)).getStatus();
}
%>
<table align="center" border="1">
<TR class="NORMAL" >
<th><bean:message key="device.name" /></th>
<th><bean:message key="device.current.status"/></th>
<th><bean:message key="device.status" /></th>
</TR>
<tr class = "NORMAL">
<td><%=names[0]%></td>
<td><%=status[0]%></td>
<TD>
<input type="radio" name="names0"
><% if (status[0].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names0" value="off"
><% if (status[1].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
<TR class = "NORMAL">
<td><%=names[1]%></td>
<td><%=status[1]%></td>
<TD>
<input type="radio" name="names1"
><% if (status[1].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names1" value="off"
><% if (status[1].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
<TR class = "NORMAL">
<td><%=names[2]%></td>
<td><%=status[2]%></td>
<TD>
<input type="radio" name="names2"
><% if (status[2].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names2" value="off"
><% if (status[2].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
<TR class = "NORMAL">
<td><%=names[3]%></td>
<td><%=status[3]%></td>
<TD>
<input type="radio" name="names3"
><% if (status[3].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names3" value="off"
><% if (status[3].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
<TR class = "NORMAL">
<td><%=names[4]%></td>
<td><%=status[4]%></td>
<TD>
<input type="radio" name="names4"
><% if (status[4].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names4" value="off"
><% if (status[4].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
<TR class = "NORMAL">
<td><%=names[5]%></td>
<td><%=status[5]%></td>
<TD>
<input type="radio" name="names5"
><% if (status[5].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names5" value="off"
><% if (status[5].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
<TR class = "NORMAL">
<td><%=names[6]%></td>
<td><%=status[6]%></td>
<TD>
<input type="radio" name="names6"
><% if (status[6].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names6" value="off"
><% if (status[6].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
<TR class = "NORMAL">
<td><%=names[7]%></td>
<td><%=status[7]%></td>
<TD>
<input type="radio" name="names7"
><% if (status[7].equalsIgnoreCase("On")){%> CHECKED<%}%>/>On
<input type="radio" name="names7" value="off"
><% if (status[7].equalsIgnoreCase("Off")){%> CHECKED<%}%>/>Off
</TD>
</tr>
</table>
<center>
<input type = "submit" name="submit" value="Submit" tabindex="2"/>
<input type = "button" name="submit" value = "Cancel" tabindex="3"/>
<input type = "reset" name="submit" value = "Reset" tabindex="4"/>
</center>
</form></td>
</tr>
</table>
</td></tr>
<TR height="10%">
<td ><%=htmlUtil.getFooter()%></td>
</TR>
</table>
</body>
</html:html>
besides other woring only check form tag and its action attribute that calls the servlet setNewStatus that is
/**
*
*/
package com.bss.servlet;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class SetNewStatus extends HttpServlet
{
private static final long serialVersionUID = 1L;
public void init() throws ServletException
{
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String redirectUrl = null;
String param = request.getParameter("sumbit");
if(param.equalsIgnoreCase("submit")){
HttpSession session = request.getSession(true);
Enumeration names = request.getParameterNames();
while(names.hasMoreElements()){
System.out.println(names.nextElement().toString());
}
//Vector devices = new Vector();
redirectUrl = "/BioSS/jsp/admin.jsp";
}
else if (param.equalsIgnoreCase("cancel")){
redirectUrl = "/BioSS/jsp/admin.jsp";
}
else if (param.equalsIgnoreCase("reset")){
redirectUrl = "/BioSS/jsp/deviceStatus.jsp";
}
response.sendRedirect(redirectUrl);
}
public void destroy()
{
super.destroy();
}
}
it does not do the actual work but here i print out all the parameter name and values of radio type input tag that are further used for database insertion etc ...
this jsp page is called from another jsp page then this jsp page calls the servlet for further processing....
i think its enough wat u asked.