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

How to get the best graphical performance out of Java2D [closed]
Running total instead of individual total?
NullPointerException using iText 5.4.4
Why is my JDBC update not working?
Basic parallel array with two Strings
Twitter Streaming API rate limit..How to deal with it?
Cant add record to sqlite database using DialogFragment
Why foreground process is faster than background process in UNIX server
How to set up bidirectional association between two objects in OO Java
How to use prolog rules in a java application [duplicate]
Hadoop slows down after map 100%
String Censoring
Move one test resource to somewhere on disk in Maven
How do I prevent Java's Mongo driver from escaping quotes in queries
Android: Filling a horizontal progress bar with user input
BufferedReader is unable to read last line in java

Categories

HOME
vbscript
netbeans
keras
webstorm
mean-stack
framework7
ip
opengl-es-2.0
indesign
bs4
gnupg
here-api
jplayer
dynamics-crm-online
seaborn
progressive-web-apps
angular-ui
errorlevel
cloudhub
language-agnostic
opennlp
publish
libuv
windows-dev-center
uiswipegesturerecognizer
mozilla
force-layout
io-redirection
main
android-fingerprint-api
bootstrap-dialog
s
convertapi
theming
python-c-api
promela
boost-multi-index
nstextview
darcs
akka-cluster
gcsfuse
nbconvert
iso8601
spring-cache
redundancy
specrun
google-cdn
elements
url-masking
transmitfile
django-debug-toolbar
pickadate
execute
collapse
python-3.2
android-listview
sonarqube5.1.2
jscript.net
qpainter
mdt
javafx-webengine
client-side-templating
document-classification
jboss-weld
xsockets.net
sitemesh
blending
cos
spring-validator
type-equivalence
kyotocabinet
angularjs-controller
coderush
word-processor
propertyeditor
php-parser
stage
data-loss
joyent
tomcat-valve
oncheckedchanged
createwindow
webkit.net
sef
uimenucontroller
putchar
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