java


how to forward iterator data from jsp to servlet


This is my admin.jsp where i get the data from search.java(the thing is a user posts a news and admin will receive all the news posts from the users.In this admin.jsp page admin can view all the posts.)
<%#page language="java" import="java.util.*" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<jsp:include page="Style.css"/>
<head>
<title>admin page</title>
</head>
<jsp:include page="nav.html"/>
<body>
<h2>Welcome Admin</h2>
<form action="/SimpleLoginForm/Search">
Enter NewsPost Status(Active/Inactive): <input type="text" name="uname"/>
<input type="submit" value="search"/>
</form>
<%Iterator itr;%>
<% List data= (List)request.getAttribute("data");
if(data != null){
%>
<table border="1" width="900">
<tr>
<td width="119"><b>POSTID</b></td>
<td width="250"><b>NewsFeed</b></td>
<td width="168"><b>Flag</b></td>
<td width="168"><b>POST</b></td>
</tr>
<%
for (itr=data.iterator(); itr.hasNext(); )
{
%>
<tr>
<td width="119"><%=itr.next()%><input type = "hidden" name = "id" value = "data"></td>
<td width="250"><%=itr.next()%><input type = "hidden" name = "news" value = "newsfeed"></td>
<td width="168"><%=itr.next()%></td>
<td width="168"><form action="/SimpleLoginForm/Submitnews" method="post">
<input type="submit" value="ok" /></input>
</td>
</form>
</tr>
<%}}%>
</table>
<form action="/SimpleLoginForm/logout" method="post">
<input type="submit" value="Logout" />
</form>
</body>
</html>
This is my search.java file
package forms;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import java.sql.*;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Search extends HttpServlet {
private ServletConfig config;
//Setting JSP page
String page="admin.jsp";
public void init(ServletConfig config)
throws ServletException{
this.config=config;
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException,IOException
{
DBConnection db=new DBConnection();
Connection con=db.getCon();
response.setContentType("text/jsp");
PrintWriter out = response.getWriter();
ResultSet rs = null;
List dataList
= new ArrayList();
try {
//Select the data from the database
String sql = "select * from newspost ";
Statement s = con.createStatement();
s.executeQuery (sql);
rs = s.getResultSet();
while (rs.next ()){
//Add records into data list
dataList.add(rs.getInt("postid"));
dataList.add(rs.getString("newsfeed"));
dataList.add(rs.getString("flag"));
}
rs.close ();
s.close ();
}catch(Exception e){
System.out.println("Exception is ;"+e);
}
request.setAttribute("data",dataList);
//Disptching request
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
if (dispatcher != null){
dispatcher.forward(request, response);
}
}
}
This is my output image
enter image description here
now my doubt is how can i get the specific row if the admin clicks on ok button to another servlet. Can anybody help with this doubt.Thank you

Related Links

Problem deploying scheduled EJB to Glassfish server
Usage of SDO_POINT from Oracle
How do I use super in java?
How to get the path to a properties file and pass it to a bean at runtime
How to use the Play Framework with Google App Engine with locally installed Java 7?
Why can't I access a remote database through Java?
What is the use of serialization? [duplicate]
Anybody knows how to export in Java data from google app engine datastore to fusion tables ?
How to remove circular dependency from two classes which are concrete types
Returning array in Java
Solr: combining EdgeNGramFilterFactory and NGramFilterFactory
java.nio.file.WatchEvent gives me only relative path. How can I get the absolute path of the modified file?
Finding a point on a Bézier curve when given the distance from the start point?
Printing a rectangle with symbols in JAVA
Why does my libGDX applet produce this SecurityException?
Problem passing String[][] from Java to R using rJava

Categories

HOME
clips
asp.net-core
proxy
iot
jsp-tags
callback
convolution
mouse
applepay
medical
elasticsearch-hadoop
midi
modx-revolution
google-cloud-spanner
gz
dynamics-crm-online
worldwind
telephony
progressive-web-apps
finite-automata
crystal-reports-2008
viewport
scichart
conemu
ml
jasonette
orleans
ehcache
kvc
underflow
intel-pin
traffic
social-media
fluentvalidation
unboundid
yadcf
xquery-3.0
oracle-fusion-middleware
fog
perlin-noise
avcapturesession
nssegmentedcontrol
appfabric
theano.scan
vapor
sqlite2
unobtrusive-validation
android-tabhost
sfdc
grid.mvc
modelmapper
convertapi
btrace
avconv
sage-one
domain-model
mu
diagnostics
webdriverjs
account-kit
eventkit
file-writing
mikroc
merge-conflict-resolution
bgp
oauth2client
asp.net5
itextpdf
freedesktop.org
kendonumerictextbox
prerequisites
intel-fortran
python-3.2
libressl
tarjans-algorithm
camanjs
android-nested-fragment
xcode-6.2
java-metro-framework
article
typeof
uitouch
picturefill
jboss-weld
meteor-velocity
mbr
page-layout
xsockets.net
ms-project-server-2010
apc
google-cloud-save
dotnetnuke-5
easy-install
pushbackinputstream
clipper
dmoz
gil
hosts-file
nsmanagedobject
buildr
dotnethighcharts
semantic-diff
data-loss
psi
inotifycollectionchanged
telerik-scheduler
visitor-statistic
dentrix
jquery-ui-droppable
routedevent
iweb
adrotator
yagni
zend-decorators
sector
spec#
signal-handling

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App