creating a webserver in netbeans with I have 3 files index.jsp, response.jsp and client.java.
the idea is to create a temperature converter, but only takes the input and not doing the calculator job.
please any help!?
index.jsp
<form name="Input Form" id="ftemp" action="response.jsp">
<input type="text" name="temp" />
<select name="conv1">
<option>Celsius</option>
<option>Fahrenheit</option>
</select>
<select name="conv2">
<option>Fahrenheit</option>
<option>Celsius</option>
</select>
<input type="submit" value="Submit" />
</form>
response.jsp
<body>
<h1>your list is in order</h1>
<jsp:useBean id="sortbean" scope="session" class="sortclient.SortClient" />
<jsp:setProperty name="sortbean" property="input" />
<jsp:setProperty name="sortbean" property="cel" />
<jsp:setProperty name="sortbean" property="fahr" />
<jsp:getProperty name="sortbean" property="input" />
</body>
client.java
public class SortClient {
private String input;
double cel = 0;
double fahr = 0;
public SortClient (){
input = null;
}
public String getInput() {
try{
String key = getKey();
input = mergeSort (input,key);
double tempCelsius = input.nextDouble();
double tempFahrenheit = input.nextDouble();
return input;
}catch (Exception ex){
System.out.println(ex); //we would log this
return "That is not a valid list";
}
}
public void setInput(String input) {
this.input = input;
}
public double toCelsius( double tempFahrenheit )
{
return ((5.0 / 9.0) * ( tempFahrenheit - 32 ));
}
public double toFahrenheit( double tempCelsius )
{
return (tempCelsius * 9.0 / 5.0) + 32;
}
private static String mergeSort(java.lang.String input, java.lang.String userKey) {
org.tempuri.Service service = new org.tempuri.Service();
org.tempuri.IService port = service.getBasicHttpBindingIService();
return port.mergeSort(input, userKey);
}
private static String getKey() {
org.tempuri.Service service = new org.tempuri.Service();
org.tempuri.IService port = service.getBasicHttpBindingIService();
return port.getKey();
}
You have multiple problems in your code. Here are some suggestions:
Match the input names in index.html and SortClient.java to avoid confusion and simplify property assignments
Create setter and getter for all fields or else jsp:setProperty and jsp:getProperty won't work
Pay attention on your data types: String doesn't have nextDouble(). If you haven't please use IDE (Eclipse, Netbeans, Intellij .etc) assistance.
Remove unnecessary libraries and code eg. org.tempuri.*
Here are codes implementing suggestions above:
index.jsp
<form name="Input Form" id="ftemp" action="response.jsp">
<input type="text" name="temp" />
<select name="conv1">
<option>Celsius</option>
<option>Fahrenheit</option>
</select>
<select name="conv2">
<option>Fahrenheit</option>
<option>Celsius</option>
</select>
<input type="submit" value="Submit" />
</form>
response.jsp
<h1>your list is in order</h1>
<jsp:useBean id="sortbean" scope="session" class="sortclient.SortClient" />
<jsp:setProperty name="sortbean" property="*" />
Input: <jsp:getProperty name="sortbean" property="temp" /><br>
Conv1: <jsp:getProperty name="sortbean" property="conv1" /><br>
Conv2: <jsp:getProperty name="sortbean" property="conv2" /><br>
Result: <jsp:getProperty name="sortbean" property="result" />
SortClient.java
package sortclient;
public class SortClient {
private String temp;
private String conv1;
private String conv2;
private Double result;
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
public String getConv1() {
return conv1;
}
public void setConv1(String conv1) {
this.conv1 = conv1;
}
public String getConv2() {
return conv2;
}
public void setConv2(String conv2) {
this.conv2 = conv2;
}
public Double getResult() {
result = Double.parseDouble(temp);
if (conv1.equalsIgnoreCase(conv2)) {
return result;
} else if (conv2.equalsIgnoreCase("Celsius")) {
return toCelsius(result);
} else if (conv2.equalsIgnoreCase("Fahrenheit")) {
return toFahrenheit(result);
}
return 0.0;
}
public double toCelsius(double tempFahrenheit )
{
return ((5.0 / 9.0) * ( tempFahrenheit - 32 ));
}
public double toFahrenheit( double tempCelsius )
{
return (tempCelsius * 9.0 / 5.0) + 32;
}
}
Refer to this tutorial for detailed guide.
As other have suggested, this approach is actually considered obsolete as it's tightly coupled and not maintainable on big scale. So I'd also suggest you to learn MVC pattern as from tutorial such as:
http://courses.coreservlets.com/Course-Materials/csajsp2.html
http://www.thejavageek.com/2013/08/11/mvc-architecture-with-servlets-and-jsp/
Related
I am trying to create a small program that takes two number as input from user via MiniAdd.jsp, adds them and then returns it on the same page. I had to make use of Javabeans in JSP. I'm not really sure what I've done. But right now I am running the code and I get [HTTP Status 500 – Internal Server Error].
org.apache.jasper.JasperException: An exception occurred processing.
Can someone please help me with where I've gone wrong and what do I need to do? Here's my code so far.
SumBeans2.java
package add;
import java.io.Serializable;
public class SumBean2 implements Serializable {
private int num1;
private int num2;
private int sum;
public SumBean2(){
}
public int getNum1() {
return num1;
}
public void setNum1(int num1) {
this.num1 = num1;
}
public int getNum2() {
return num2;
}
public void setNum2(int num2) {
this.num2 = num2;
}
public int getSum() {
return sum;
}
public void setSum(int sum) {
this.sum = sum;
}
}
MiniAdd.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# page import="add.SumBean2"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Sum</title>
</head>
<body>
<form action="MiniAdd.jsp">
<label>Number 1</label><input type="text" name="num1"><br>
<label>Number 2</label><input type="text" name="num2"><br>
<input type="submit" value="Submit"/>
<input type="reset" value="Reset"/>
<jsp:useBean id="SumNumber" class="add.SumBean2" scope="session"/>
<jsp:setProperty name="SumNumber" property="num1" value='<%=request.getParameter("num1") %>'/>
<jsp:setProperty name="SumNumber" property="num2" value='<%=request.getParameter("num2") %>'/>
</form>
<%
int sum = 0;
try {
sum = Integer.parseInt(request.getParameter("num1"))+Integer.parseInt(request.getParameter("num2"));
} catch(Exception e) {}
%>
<jsp:setProperty name="SumNumber" property="sum" value='<%= request.getParameter("sum") %>'/>
Sum = <jsp:getProperty name="SumNumber" property="sum"/>
</body>
</html>
I have a problem with my web server. i need to introducing parametre and after introducing use that value in calcule in class. after calculate i need to show that value after press ok button
package CalculatorOnline;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
#WebServlet("/TestCalc")
public class TestCalc extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
int Prescale = Integer.parseInt(request.getParameter("prescaler"));
int TimerMO = Integer.parseInt(request.getParameter("timermode"));
long TTTicks = Integer.parseInt(request.getParameter("ttticks"));
double Freq = Integer.parseInt(request.getParameter("freq"));
System.out.println("Frecventa:"+ Freq);
System.out.println("Prescaler:"+ Prescale);
System.out.println("TimerMod:"+ TimerMO);
System.out.println("TotalTimerTicks"+ TTTicks);
TestLabclass temp = new TestLabclass();
temp.setFreq(Freq);
temp.setPrescaler(Prescale);
temp.setTTTicks(TTTicks);
PrintWriter out = response.getWriter();
double TimeU2 = temp.getTimeU();
double RealT = temp.getRealT();
out.println("Timpului pina la umplere : "+ TimeU2);
out.println("Real time per tick : "+ RealT);
}
}
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form name="Frec input" action="TestLab">
<p> <label>FREQUENCY</label>
<input type="number" name="freq" id="quantity" />
<label>Total Timer Ticks</label>
<input type="number" name="ttticks" id="quantity" />
<label>Prescaler</label>
<select name="prescaler">
<option value="0">No clock source</option>
<option value="1">No Prescaling</option>
<option value="8">clkI/O/8</option>
<option value="64">clkI/O/64</option>
<option value="256">clkI/O/256</option>
<option value="1024">clkI/O/1024</option>
</select>
<label>Mode</label>
<select name="timermode">
<option value="0">Normal</option>
<option value="1">PWM</option>
<option value="2">CTC</option>
<option value="3">Fast PWM</option>
</select>
<input type="submit" value="ok" />
</p>
</form>
</body>
</html>
enter image description here
I am introducing all data i need and after press ok button i have 404 error. My out parametre was not showing
classfile
package CalculatorOnline;
class TestLabclass {
double Freq; // frequency
double TimeU; // overflow time
double RealT; //real time per tick
int Prescaler;
long TTTicks;
long OverFlowCount;
public TestLabclass()
{
Freq = 0;
TimeU = 0;
RealT = 0;
Prescaler = 0;
TTTicks = 0;
OverFlowCount = 0;
}
public double getFreq()
{
return Freq;
}
public void setFreq(double Freq)
{
this.Freq = Freq;
}
public int getPrescaler()
{
return Prescaler;
public void setPrescaler(int Prescaler)
{
this.Prescaler = Prescaler;
}
public long getTTTicks()
{
return TTTicks;
}
public void setTTTicks(long TTTicks)
{
this.TTTicks = TTTicks;
}
public double getRealT() {
return TTTicks/(Freq/Prescaler);
}
public void setRealT(double RealT)
{
this.RealT = RealT;
}
public void setOverFlowCount(long OverFlowCount)
{
this.OverFlowCount = OverFlowCount;
}
public long getOverFlowCount()
{
return TTTicks/256;
}
public double getTimeU()
{
return RealT*(TTTicks - (OverFlowCount * 256));
}
public void setTimeU(double TimeU)
{
this.TimeU = TimeU;
}
}
The form action should match the name declared in #WebServlet("/TestCalc")
Replace
<form name="Frec input" action="TestLab">
with
<form name="Frec input" action="TestCalc">
-OR-
Replace #WebServlet("/TestCalc") with #WebServlet("/TestLab")
I have an iterator which requires to use mapped properties or indexed properties but my getter-setter are not getting those values.
For Ex:
(This is just an example. Ultimately the idea is whether I can use mapped property in struts 2 or not. If yes, then how.)
index.jsp:
<s:form action="hello" namespace="foo">
<s:textfield name="arp(0)" /> <br/>
<s:textfield name="prp(0)" /> <br/>
<s:textfield name="arp(1)" /> <br/>
<s:textfield name="prp(1)" /> <br/>
<s:submit value="Say Hello" />
</s:form>
helloWorld.action:
class PRLists {
String arp;
String prp;
public String getArp() {
return Arp;
}
public void setArp(String aRP) {
arp = aRP;
}
public String getPrp() {
return prp;
}
public void setPrp(String pRP) {
prp = pRP;
}
}
public class HelloWorldAction {
ArrayList<PRLists> prlist = new ArrayList<PRLists>();
public String execute() throws Exception {
System.out.println("ruuning execute");
return "success";
}
public ArrayList<PRLists> getPrlist() {
return prlist;
}
public void setPrlist(ArrayList<PRLists> prlist) {
this.prlist = prlist;
}
public String getArp(String key) {
int index = Integer.parseInt(key);
return prlist[index].arp;
}
public void setArp(String key, Object value) {
System.out.println("set ARP: index:" + index + ", value" + value);
int index = Integer.parseInt(key);
prlist[index].arp = value.toString();
}
public String getPrp(String key) {
int index = Integer.parseInt(key);
return prlist[index].prp;
}
public void setPrp(String key, Object value) {
System.out.println("set PRP, Key:" + key + ", value:" + value);
int index = Integer.parseInt(key);
prlist[index].prp = value.toString();
}
}
Earlier I was having this kind of working functions in struts 1 but now I am trying to move it to struts 2. Now my setter functions in HelloWorldAction.java for arp and prp are not getting called upon form submit.
public void setArp(String key, Object value);
public void setPrp(String key, Object value);
<s:textfield name="prlist[0].arp" /> can work but we have some dependent code which requires to use fields with name such as <s:textfield name="arp(0)" />.
I do not know whether struts 2 supports mapped properties or not. If it supports, then how can I use it.
I also found a related issue: https://issues.liferay.com/browse/LPS-14128
Note: I have made some modifications in question description
Thanks in advance.
You're violating a lot of "rules" here, other than avoiding almost any mechanism provided by the framework. Never put logic in accessors / mutators (getters / setters), never use capitalized variable names, avoid using variables starting with an uppercase letter, read struts Type Conversion, use Struts tags (eg. <s:textfield/> instead of <input type="text" />) whenever possible, and reduce your code to:
public class HelloWorldAction{
private String name;
private List<PRLists> arnList = new ArrayList<PRLists>();
public String execute() throws Exception {
System.out.println("running execute");
return "success";
}
public List<PRLists> getArnList(){
return arnList;
}
public void setArnList(List<PRLists> arnList){
this.arnList = arnList;
}
public String getName() {
return name;
}
public void setName(String name) {
System.out.println("set name: "+name);
this.name = name;
}
}
<s:form action="hello" namespace="foo">
<s:textfield name="name" label="name" />
<s:textfield name="arnList[0].arp" /> <br/>
<s:textfield name="arnList[0].prp" /> <br/>
<s:textfield name="arnList[1].arp" /> <br/>
<s:textfield name="arnList[1].prp" /> <br/>
<s:submit value="Say Hello" />
</s:form>
of in an iterator, as you said (without showing it), like
<s:form action="hello" namespace="foo">
<s:textfield name="name" label="name" />
<s:iterator value="arnList" status="rowStatus">
<s:textfield name="arnList[%{#rowStatus.index}].arp" /> <br/>
<s:textfield name="arnList[%{#rowStatus.index}].prp" /> <br/>
</s:iterator>
<s:submit value="Say Hello" />
</s:form>
I have the following JSP:
<jsp:useBean id="trackingBean" class="tracking.Tracking" scope="session">
<jsp:setProperty name="trackingBean" property="*" />
</jsp:useBean>
<form action="TrackingController" method="post">
<div id="upper_frequency">
Upper Freq: <input type="text" name="upperFreq"
>
</div>
<div id="lower_frequency">
Lower Freq: <input type="text" name="lowerFreq"
>
</div>
<div id="if_frequency">
IF Freq: <input type="text" name="ifFreq"
>
</div>
<div id="cap_high">
Tuning Cap highest value: <input type="text" name="capHigh"
>
</div>
<div id="cap_low">
Tuning Cap lowest value: <input type="text" name="capLow"
>
</div>
<input type="submit" value="Submit" />
</form>
This should pass on the trackingBean to the sevlet whose doGet, the same as doPost:
doGet..
{
Tracking trackingBean = (Tracking) request.getSession(),getAttribute("tackingBean");
....
}
trackingBrean is not null, but all the values are never set?
The bean is:
package tracking;
public class Tracking {
public Tracking() {
}
private double upperFreq;
private double lowerFreq;
private double ifFreq;
private double capHigh;
private double capLow;
public double getUpperFreq() {
return upperFreq;
}
public void setUpperFreq(double upperFreq) {
this.upperFreq = upperFreq;
}
public double getLowerFreq() {
return lowerFreq;
}
public void setLowerFreq(double lowerFreq) {
this.lowerFreq = lowerFreq;
}
public double getIfFreq() {
return ifFreq;
}
public void setIfFreq(double ifFreq) {
this.ifFreq = ifFreq;
}
public double getCapHigh() {
return capHigh;
}
public void setCapHigh(double capHigh) {
this.capHigh = capHigh;
}
public double getCapLow() {
return capLow;
}
public void setCapLow(double capLow) {
this.capLow = capLow;
}
}
You're requesting "tackingBean" don't you need "trackingBean" ?
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="/struts-tags" prefix="s"%>
<%# taglib prefix="sj" uri="/struts-jquery-tags"%>
<jsp:include page="checkLogin.jsp" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Allocate Tans</title>
<script type="javascript" src="jquery-1.7.js"></script>
<sj:head jqueryui="true" jquerytheme="cupertino" />
</head>
<script type="text/javascript">
$(document).ready(function()
{
$('#batchID').change(function(event) {
var batch=$('#batchID').val();
$.ajax({
url : "doShowAllocationStatus.action",
data : "batch="+batch,
success : function(html) {
$('#table').html(html);
},
error : function(html) {
alert("error");
}
});
});
});
</script>
<body>
<div id=table>
<s:form action="doAllocate" name="allocate" executeResult="true">
<s:actionerror />
<s:actionmessage />
<s:select label="Select Batch" headerKey="-1"
headerValue="Select a Batch..." list="%{#session.Batchs}"
Value="batch" name="batch" id="batchID" />
<s:select label="Select User" headerKey="-1"
headerValue="Select an User..." list="%{#session.users}" name="user"
value="user" />
<s:radio list="#{'Curator':'Curator','QC':'QC'}" name="user_work_as" />
<s:submit value="Allocate" id="AllocateID" />
<table align="center" border="2" width="800">
<tr>
<th>TAN</th>
<th>Curator</th>
<th>Curator Status</th>
<th>QC</th>
<th>QC Status</th>
</tr>
<s:iterator value="allocationList" var="tableID">
<tr>
<td><s:checkbox name="Tans" fieldValue="%{#tableID.tan}"
theme="simple" />
<s:property value="tan" /></td>
<td><s:property value="curator" /></td>
<td><s:property value="curator_status" /></td>
<td><s:property value="qc" /></td>
<td><s:property value="qc_status" /></td>
</tr>
</s:iterator>
</table>
</s:form>
</div>
</body>
</html>
In this when I use the for all content inside the dropdown select works fine as i expected for dropdown list and table but it react different I mean the table is appended with same rows once again when I submit and if I select some thing in batch dropdown list then the table comes to it correct list. If I used only for table, it prints the full page once again. I can understand what had happen, but could not find solution to achieve what I need.
My aim is to display the table based on the batch selected and the submit should do what it actually has to do.
server side code...
package controller;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import model.BatchInfo;
import model.CationDAO;
//import org.apache.struts2.interceptor.SessionAware;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
#SuppressWarnings("serial")
public class AllocateTAN extends ActionSupport {
//Fields that hold data...
private List<BatchInfo> allocationList =new ArrayList<BatchInfo>();
private String batch;
private List<String> batchs = new ArrayList<String>();
private String TAN;
private String Tans[];
private String user;
private List<String> users = new ArrayList<String>();
private String user_work_as;
//getters and setters....
public List<BatchInfo> getAllocationList() {
return allocationList;
}
public void setAllocationList(List<BatchInfo> allocationList) {
this.allocationList = allocationList;
}
//#RequiredStringValidator(message = "Batch Not Selected")
public String getBatch() {
return batch;
}
public void setBatch(String batch) {
this.batch = batch;
}
public List<String> getBatchs() {
return batchs;
}
public void setBatchs(List<String> batchs) {
this.batchs = batchs;
}
//#RequiredStringValidator(message = "TAN Not Selected")
public String getTAN() {
return TAN;
}
public void setTAN(String tAN) {
TAN = tAN;
}
public String[] getTans() {
return Tans;
}
public void setTans(String[] tans) {
Tans = tans;
}
//#RequiredStringValidator(message = "Worker Not Selected")
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public List<String> getUsers() {
return users;
}
public void setUsers(List<String> users) {
this.users = users;
}
//#RequiredStringValidator(message = "Select Any One")
public String getUser_work_as() {
return user_work_as;
}
public void setUser_work_as(String user_work_as) {
this.user_work_as = user_work_as;
}
//variable used to access DataBase...
CationDAO dao1 = new CationDAO() ;
//flow 1.: making all details available for the allocate TAN page...when page page is loaded 1st time
public String AllocatingTANpageDetails() throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
this.batchs=dao1.Batch_List();
session.put("Batchs", batchs);
//Tans=dao1.Tan_list(getBatch());
this.users=dao1.Users_List();
session.put("users", users);
return SUCCESS;
}
/*TAN list
private void showTANlist(String Batch1) throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
Tans=dao1.Tan_list(Batch1);
session.put("Tans", Tans);
}*/
//flow 2.: showing Allocation Status in Table form...in same page
public String showAllocationStatus() throws SQLException {
System.out.println("Inside Show Allocation Status");
if(batch==null||"-1".equals(batch)){
addActionMessage("Please!... Select a Batch");
return ERROR;
}
Map<String, Object>session=ActionContext.getContext().getSession();
//setBatch(batch_value);
String bth=getBatch();
if (bth==null || bth=="-1"){
System.out.println("batch is empty "+bth);
}
System.out.println(bth);
session.put("Batch",bth);
// showTANlist(bth);
System.out.println("Processing Allocation List... ");
this.allocationList=(List<BatchInfo>)dao1.status(bth);
System.out.println(allocationList);
session.put("AllocationList",allocationList);
System.out.println("Finished...");
return SUCCESS;
}
//execute method form allocating a TAN for a user...
public String execute(){
String statusTable=null;
String er = null;
if(Tans==null||"-1".equals(Tans)){
addActionError("Please!... Select a TAN"); er="er";
}
if (user==null||"-1".equals(user)){
addActionError("Please!... Select an Worker");er="er";
}
if (user_work_as==null||user_work_as==""||"-1".equals(user_work_as)){
addActionError("Please!... Select either Curation or QC");er="er";
}
try {
statusTable=showAllocationStatus();
} catch (SQLException e) {
e.printStackTrace();
}
if(!"er".equals(er)&& "success".equals(statusTable)){
System.out.println("inside Execute metho of AllocateTAN.java");
if ("QC".equalsIgnoreCase(user_work_as)){
try {
if(!"Complete".equalsIgnoreCase(dao1.CheckCurator(batch,Tans))){
addActionMessage("Curation Not yet completed");
return ERROR;
}
dao1.AllocateTANforUser( batch, Tans, user, user_work_as);
this.allocationList=(List<BatchInfo>)dao1.status(getBatch());
return SUCCESS;
} catch (SQLException e) {
e.printStackTrace();
}
}else if("Curator".equalsIgnoreCase(user_work_as)){
try {
dao1.AllocateTANforUser( batch, Tans, user, user_work_as);
} catch (SQLException e) {
e.printStackTrace();
}
this.allocationList=(List<BatchInfo>)dao1.status(getBatch());
return SUCCESS;
}
}
return ERROR;
}
}
First, I would suggest that you change your structure as you are using AJAX hardly at all (you only use one on load and that's it, and that is not different than passing all those values from the very beginning from the action). As you only have 3 values to pass, is fairly easy to capture them with jQuery("#myid").val() and pass them with jQuery.ajax. something like
<s:button value="Allocate Me!!!" onclick="allocating_you()"/>
and then
function allocationg_you(){
var val1 = jQuery("#value1").val();
var val2 = jQuery("#value2").val();
var val3 = jQuery("#value3").val();
jQuery.ajax({
url: "allocator",
data: "val1=" + val1 +"&val2=" + val2 + "&val3=" + val3 + "&r=" //dont forget to add a random number
success: function(data){
jQuery("#mytable").html(data).load();
}
});
}
finally, you should reduce the ajax refreshment to the minimun necessary, as it will be easier to mantain and to give aesthetics. so for example your template should be divided like this
<your form>
<your table header>
<div id="mytable">
with this template you would only have to refresh the actual content and everything else will remain intact (true AJAX), so in your JSP response for your AJAX call there should be only the iterator part. you will even be able to create the table with a scrollbar and a static header, only needing to put some matching sizes in your ajax cells along with the table tag.
Hope this helps you. If you manage to crack this you will be able to do wonders. jQuery + Struts2 + (seems that you are not using Hbernate, but oh well) it's a monstrous combination.