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

Extract specific string from String [closed]
H2 Trigger crashes and destroy Database
Working of Try - Catch and Finally [closed]
JSTL cannot find bean that is a forEach iteration
Java Cannot Find Symbol Error In Do loop
JavaFX changes new Scene to Caspian stylesheet
How do I extract data from pptx file using Apache POI?
immutable class objects [closed]
How to remove records from table in bulk with hibernate hql?
Print accentuation (UTF-8) Zebra cpcl Java/Android
How to read elements of arraylist of a class defined in another class in java?
ANDROID [Back Button causes crash]
JavaFX 8 - Bind TableView Selection Model Property
Visible ToolTipText at different positions simultenously?
Embedded Jetty server
Unable to execute multiple SQL queries with Data Source connection

Categories

HOME
maven
osgi
ngrx
plot
iterator
xmpp
rdf
retrofit
echarts
android-youtube-api
facebook-php-sdk
vifm
spring-xd
etl
vb.net-2010
phaser
size
libtiff
highlight.js
oxyplot
django-cms
dbext
jtextfield
autoconf
tar
claims-based-identity
wijmo
icloud-api
angular2-aot
microsoft-chart-controls
stringtemplate
lxd
repo
geopositioning
mpmediaquery
hexo
io-redirection
gzipstream
turbogears
http-redirect
reactive-cocoa-5
babel-core
auto-update
jsch
dotcover
xml-documentation
rails-routing
promela
pnotify
aurelia-validation
knockout-components
directory-structure
feeds
media-player
sqlbulkcopy
google-cdn
android-fonts
vmware-tools
infix-notation
player
ios4
spim
wso2cloud
cakephp-3.1
method-parameters
sniffer
unity5.2.3
p2
network-interface
onactivityresult
ceil
doskey
ccss
gridfs
inbox
soundtouch
rabl
enterprisedb
broken-links
runas
frameset
pysimplesoap
assembly-loading
cufon
vdsp
joyent
sortable-tables
jquery-ui-droppable
modelstate
bespin
fixed-width
swing-app-framework
simpletest
ugc

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