Im getting a curious error with an ArrayList, below is the code (note that this code was copied from an online servlet example, I am a JAVA novice).
the JSP:
<%#page import="p.SecondExample"%>
<%# page language="java" import="java.util.*;"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Servlet Application</TITLE>
<script language="javascript">
function editRecord(id){
window.location.href="editServlet/"+id;
}
function deleteRecord(id){
window.location.href="deleteUser/"+id;
}
</script>
</HEAD>
<BODY>
<br>
<table align="center">
</table>
<br>
<table width="600px" align="center" style="background-color:#EDF6EA;border:1px solid #000000;">
<tr><td colspan=9 align="center" height="10px"></td></tr>
<tr><td colspan=9 align="center"><!-- Add New User--></td></tr>
<tr><td colspan=9 align="center" height="10px"></td></tr>
<tr style="background-color:#7BA88B;font-weight:bold;">
<td>Sector Segment</td><td>Color</td>
</tr>
<%
String bgcolor="";
int count=0;
List viewList = new ArrayList();
Iterator viewItr;
SecondExample se = new SecondExample();
se.doPost(request, response);
if(request.getAttribute("userList")!=null && request.getAttribute("userList")!="")
{
List userList = (ArrayList)request.getAttribute("userList");
Iterator itr = userList.iterator();
System.out.println(userList);
while(itr.hasNext())
{
if(count%2==0)
{
bgcolor = "#C8E2D1";
}
else
{
bgcolor = "#EAF8EF";
}
viewList = (ArrayList)itr.next();
int id = Integer.parseInt(viewList.get(0).toString());
viewItr = viewList.iterator();
%>
<tr style="background-color:<%=bgcolor%>;">
<%
while(viewItr.hasNext())
{
%>
<td><%=viewItr.next()%></td>
<%
}
count++;
%>
<td><input type="button" name="edit" value="Edit" style="background-color:#49743D;font-weight:bold;color:#ffffff;" onclick="editRecord(<%=id%>);" ></td>
<td><input type="button" name="delete" style="background-color:#ff0000;font-weight:bold;;color:#ffffff;" value="Delete" onclick="deleteRecord(<%=id%>);"></td>
</tr>
<%
}
}
if(count==0)
{
%>
<tr><td colspan="9" align="center"> </td></tr>
<tr><td colspan="9" align="center">No Record Avaliable</td></tr>
<%
}
%>
<tr><td colspan=9 align="center" height="2px"></td></tr>
</table>
</BODY>
</HTML>
in debug, the error appears to occur with:
viewList = (ArrayList)itr.next();
int id = Integer.parseInt(viewList.get(0).toString());
viewItr = viewList.iterator();
where my error appears as:
org.apache.jasper.JasperException: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.ArrayList
I'm not quite sure why or how to make next a string. Any help is greatly appreciated.
Yep, itr.next() returns a String, which cannot be cast into an ArrayList.
String value = (String) itr.next();
int id = Integer.parseInt(value);
The following few lines of code in which you're iterating over your viewArray can be removed now, too.
Related
I have a code that should display data on the page of the model
<% if (patients) { %>
<% patients.each { %>
<tr>
<td>${ ui.format(it.status) }</td>
<td align="center">
<% def linkClaim="patientView.page?patientId=' + ${patientId}+ '&claimUuid=" + ${it.uuid} %>
<button onclick="location.href='${linkClaim}'" type="button">Details</button>
</td>
</tr>
<% } %>
Data from the model:
patients
patientId
Error:
groovy.lang.MissingMethodException: No signature of method: SimpleTemplateScript171.$()
Please help me to solve a problem!
I have table created in JSP and filled with data from my DB, and the problem is - I have not idea how to access that JSP data from my controller.
For example - I need to pass appropriate ID (just String) to my controller from JSP to execute Delete method.
My jsp:
<body>
<form action="/editCategory" method="POST">
<h3>Existing categories</h3>
<%
List<Category> categories = (List<Category>) request.getAttribute("model");
if (categories != null) {
%>
<table border="1">
<tr>
<th width="24">ID</th>
<th width="80">Name</th>
<%--<th></th>--%>
</tr>
<%
for (Category category : categories) {
%>
<tr>
<td><%= category.getId() %> <% request.setAttribute("id", category.getId());%>
</td>
<td><%= category.getName() %>
</td>
<td>
<input type="submit" name="delete" value="Delete"/>
</td>
</tr>
<%
}
%>
</table>
<%
} else {
%>
<b>Categories list is empty :(</b>
<%
}
%>
</form>
</body>
My controller methods:
public Model getModel(HttpServletRequest req, HttpServletResponse resp) throws DBException
{
if (req.getParameter("submit")!=null){
addCategory(req);
}
if (req.getParameter("delete")!=null){
deleteCategory(req);
}
categories = categoryDAO.getCategories();
return new Model("/editCategory.jsp", categories);
}
private void deleteCategory(HttpServletRequest req) {
System.out.println(req.getAttribute("id") + " printed");
}
For now I want just to see that correct ID is taken!
Please help!
you could do it this way:
<%
for (Category category : categories) {
%>
<tr>
<td><%= category.getId() %>
<input type="hidden" name="allIds" value="<%= category.getId() %>" /></td>
<td><%= category.getName() %>
</td>
<td>
<input type="submit" name="delete" value="Delete"/>
</td>
</tr>
<%
}
%>
as the type says hidden is not visible.
after that read the values in your servlet with:
String[] lAllIds = request.getParameterValues("allIds");
I encountered this error while working on a web application for google app engine,through this tutorial.http://www.vogella.com/tutorials/GoogleAppEngineJava/article.html. Would like to hear more advice from you. Thank you.
HTTP ERROR 500
Problem accessing /. Reason:
Unable to compile class for JSP:
An error occurred at line: 34 in the jsp file: /TodoApplication.jsp
Type mismatch: cannot convert from List<Todo> to List<Todo>
31: if (user != null){
32: url = userService.createLogoutURL(request.getRequestURI());
33: urlLinktext = "Logout";
34: todos = dao.getTodos(user.getUserId());
35: }
36:
37: %>
Stacktrace:
Caused by:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 34 in the jsp file: /TodoApplication.jsp
Type mismatch: cannot convert from List<Todo> to List<Todo>
31: if (user != null){
32: url = userService.createLogoutURL(request.getRequestURI());
33: urlLinktext = "Logout";
34: todos = dao.getTodos(user.getUserId());
35: }
36:
37: %>
<%# page contentType="text/html;charset=UTF-8" language="java" %>
<%# page import="java.util.List" %>
<%# page import="com.google.appengine.api.users.User" %>
<%# page import="com.google.appengine.api.users.UserService" %>
<%# page import="com.google.appengine.api.users.UserServiceFactory" %>
<%# page import="de.vogella.gae.java.todo.model.Todo" %>
<%# page import="de.vogella.gae.java.todo.dao.Dao" %>
TodoApplication.jsp
<!DOCTYPE html>
<%#page import="java.util.ArrayList"%>
<html>
<head>
<title>Todos</title>
<link rel="stylesheet" type="text/css" href="css/main.css"/>
<meta charset="utf-8">
</head>
<body>
<%
Dao dao = Dao.INSTANCE;
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String url = userService.createLoginURL(request.getRequestURI());
String urlLinktext = "Login";
List<Todo> todos = new ArrayList<Todo>();
if (user != null){
url = userService.createLogoutURL(request.getRequestURI());
urlLinktext = "Logout";
todos = dao.getTodos(user.getUserId());
}
%>
<div style="width: 100%;">
<div class="line"></div>
<div class="topLine">
<div style="float: left;"><img src="images/todo.png" /></div>
<div style="float: left;" class="headline">Todos</div>
<div style="float: right;"><%=urlLinktext%> <%=(user==null? "" : user.getNickname())%></div>
</div>
</div>
<div style="clear: both;"/>
You have a total number of <%= todos.size() %> Todos.
<table>
<tr>
<th>Short description </th>
<th>Long Description</th>
<th>URL</th>
<th>Done</th>
</tr>
<% for (Todo todo : todos) {%>
<tr>
<td>
<%=todo.getShortDescription()%>
</td>
<td>
<%=todo.getLongDescription()%>
</td>
<td>
<%=todo.getUrl()%>
</td>
<td>
<a class="done" href="/done?id=<%=todo.getId()%>" >Done</a>
</td>
</tr>
<%}
%>
</table>
<hr />
<div class="main">
<div class="headline">New todo</div>
<% if (user != null){ %>
<form action="/new" method="post" accept-charset="utf-8">
<table>
<tr>
<td><label for="summary">Summary</label></td>
<td><input type="text" name="summary" id="summary" size="65"/></td>
</tr>
<tr>
<td valign="description"><label for="description">Description</label></td>
<td><textarea rows="4" cols="50" name="description" id="description"></textarea></td>
</tr>
<tr>
<td valign="top"><label for="url">URL</label></td>
<td><input type="url" name="url" id="url" size="65" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Create"/></td>
</tr>
</table>
</form>
<% }else{ %>
Please login with your Google account
<% } %>
</div>
</body>
</html>
I built and ran the very good Google App Engine Tutorial for Java (Todo list with JPA) with no problems at all. The platform was GAE SDK 1.8.9, Eclipse 3.8, OpenJDK 7u21 and Debian Testing (jessie). This result verifies the correctness of all the tutorial source code. Your problem is somewhere in your local installation.
Probably, the instance returned by your dao.getTodos method, is not from a class that implements java.util.List interface.
The line
34: todos = dao.getTodos(user.getUserId());
clobbers the reference to ArrayList assigned earlier to todos. Instead try
todos.addAll( dao.getTodos(user.getUserId()) );
I get this error message
pageContext cannot be resolved
but I have no variable pagecontext.
This is the code (I know there are other problems here that are beyond the scope of this question):
<%#page import="se.prv.pandora.arendeprocess.util.PandoraPersonHandler"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%# page import="org.apache.log4j.Logger" %>
<%# page import="java.util.List" %>
<%# page import="java.util.ArrayList" %>
<%# page import="java.util.HashMap" %>
<%# page import="java.util.Set" %>
<%# page import="java.util.Map" %>
<%# page import="se.prv.pandora.arendeprocess.general.ArendeProcessLocator"%>
<%# page import="se.prv.pandora.arendeprocess.page.ArendeProcessPageController" %>
<%# page import="se.prv.pandora.arendeprocess.page.GrunduppgifterPageController" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Navigation" %>
<%# page import="se.prv.pandora.arendeprocess.obj.AnsokanInfo" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Oversikt" %>
<%# page import="se.prv.pandora.arendeprocess.obj.PersonInfo" %>
<%# page import="se.prv.pandora.arendeprocess.obj.PersonInfoIndex" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Land" %>
<%# page import="se.prv.pandora.arendeprocess.obj.ArendesokInfo" %>
<%# page import="se.prv.pandora.arendeprocess.entity.Prioritet" %>
<%# page import="se.prv.pandora.arendeprocess.util.PandoraFieldConstants" %>
<%# page import="se.prv.pandora.arendeprocess.entity.Deposition" %>
<%# page import="se.prv.pandora.arendeprocess.util.ArendeComparatorManager" %>
<%# page import="se.prv.pandora.arendeprocess.obj.ArendeSearchAdmin" %>
<%# page import="se.prv.framework.forms.IFormData" %>
<%# page import="se.prv.framework.general.Action" %>
<%# page import="java.util.Iterator" %>
<%# page import="java.text.DateFormat" %>
<%# page import="java.text.SimpleDateFormat" %>
<%#page import="se.prv.pandora.arendeprocess.obj.ArendeProcessSessionData"%>
<%# page import="se.prv.pandora.arendeprocess.util.PandoraConstants" %>
<%#page import="se.prv.pandora.arendeprocess.entity.PRVNummerPerson"%>
<%# page import="se.prv.pandora.arendeprocess.entity.Region" %>
<%# page import="se.prv.pandora.arendeprocess.obj.Land" %>
<%# page import="se.prv.pandora.arendeprocess.entity.LandKod" %>
<%# page import="se.prv.pandora.arendeprocess.util.MessageHandler" %>
<%#page import="se.prv.pandora.arendeprocess.general.PandoraManager"%>
<html>
<head><link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css">
<link href="css_js/styles.css" rel="stylesheet" type="text/css">
<link href="css_js/positions.css" rel="stylesheet" type="text/css">
<link href="css_js/dialog_box.css" rel="stylesheet" type="text/css">
<link href="css_js/floats.css" rel="stylesheet" type="text/css">
<script language="JavaScript1.2" src="css_js/jquery-1.7.1.min.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/jquery-ui-1.8.17.custom.min.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/sorttable.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/general_arendeprocess.js" type="text/javascript"></script>
<script language="JavaScript1.2" src="css_js/dialog_box.js" type="text/javascript"></script>
<script language="JavaScript1.2" type="text/javascript">
function ingVar(x) {
var applicationDependence;
applicationDependence = x;
document.getElementById('ff').style.display='none';
document.getElementById('avd').style.display='none';
document.getElementById('utb').style.display='none';
document.getElementById('oepa').style.display='none';
document.getElementById('aooep').style.display='none';
if (applicationDependence == 'ff'){
document.getElementById('ob').style.display='none';
document.getElementById('ff').style.display='';
}
if (applicationDependence == 'avd'){
document.getElementById('ob').style.display='none';
document.getElementById('avd').style.display='';
}
if (applicationDependence == 'utb'){
document.getElementById('ob').style.display='none';
document.getElementById('utb').style.display='';
}
if (applicationDependence == 'oepa'){
document.getElementById('ob').style.display='none';
document.getElementById('oepa').style.display='';
}
if (applicationDependence == 'aooep'){
document.getElementById('ob').style.display='none';
document.getElementById('aooep').style.display='';
}
if (applicationDependence == 'ob'){
document.getElementById('ob').style.display='';
}
}
function popup() {
//alert('opening popup');
var popup = $('.newpopup');
popup.draggable();
//popup.resizable();
//popup.html('<p>Where is pancakes house?</p>');
//popup.show('fast');
//Comment me out and use the version below to show working
$.ajax({url:'/PandoraArendeWeb/popup.jsp',
error: function() {
alert('Error');
},
success: function(data) {
popup.html(data);
popup.show('fast');
}
}
);
/*
popup.html("test");
popup.show('fast');
*/
var screen_width = $(document).width();
var screen_height = $(document).height();
var box_width = popup.width();
var box_height = popup.height();
var top = (screen_height - box_height) / 2; // you might like to subtract a little to position it slightly higher than half way
var left = (screen_width - box_width) / 2;
popup.css({ 'position': 'absolute', 'top':top, 'left':left, 'overlayShow':true,'transitionIn' : 'elastic','transitionOut' : 'elastic','opacity' : '0.80' });
}
$(".newpopup").css('background-color', 'white');
$(document).ready(function(){
$('button').click(function(){
popup();
});
})
function popup2() {
alert('test');
var popup = $('.newpopup');
popup.draggable();
//popup.resizable();
//popup.html('<p>Where is pancakes house?</p>');
//popup.show('fast');
$.get('/PandoraArendeWeb/popup.jsp', function(data) {
popup.html(data);
popup.show('fast');
});
var screen_width = $(document).width();
var screen_height = $(document).height();
var box_width = popup.width();
var box_height = popup.height();
var top = (screen_height - box_height) / 2; // you might like to subtract a little to position it slightly higher than half way
var left = (screen_width - box_width) / 2;
popup.css({ 'position': 'absolute', 'top':top, 'left':left });
}
$(document).ready(function(){
$('#mypopup').click(function(){
popup();
});
})
$(document).ready(function() {
var $dialog = $('<div></div>')
.html('This dialog will show every time!')
.dialog({
autoOpen: false,
title: 'Basic Dialog'
});
$('#opener').click(function() {
$dialog.dialog('open');
// prevent the default action, e.g., following a link
$("#opener").load('PandoraArendeWeb/popup.jsp').dialog({modal:true});
return false;
});
});
</script>
<title>Ingivningsdag - NAT. - Pandora </title>
</head>
<%
final Logger logger = Logger.getLogger("arendeprocess_grunduppgifter.jsp");
ArendeProcessPageController apc = new ArendeProcessPageController(request);
GrunduppgifterPageController pc = new GrunduppgifterPageController(request);
ArendeProcessSessionData sessionData =(ArendeProcessSessionData) PandoraManager.getSessionData(request);
String arendeTyp = apc.getArendeTyp();
boolean showSearch = false;
boolean showSearchD = false;
boolean showSearchP = false;
boolean showSearchI = false;
boolean showSearchR = false;
boolean showSearch2 = false;
boolean showSearchF = false;
boolean showSearchA = false;
boolean showSearchU = false;
boolean showSearchO = false;
boolean showSearchEPa = false;
boolean showSearchEPn = false;
AnsokanInfo ansokanInfo = apc.getAnsokanInfo();
PersonInfo editPerson = new PersonInfo();
PersonInfo editOmbud = new PersonInfo();
String chosenPersonTyp = "";
String chosenPersonOrdNr = "";
if(ansokanInfo != null && ansokanInfo.hasEditPersonInfo()) {
editPerson = ansokanInfo.getEditPersonInfo();
Action latestAction = sessionData.getLatestAction();
chosenPersonTyp = latestAction.getActionModifier();
//+1 eftersom listindex börjar på 0
chosenPersonOrdNr = latestAction.getCurrIndexAsInt()+1+"";
} else {
editPerson.setFornamn(apc.getNyregPerson().getFornamn());
editPerson.setEfternamn(apc.getNyregPerson().getEfternamn());
editPerson.setForetag(apc.getNyregPerson().getForetag());
//editPerson.setOrgnr(apc.getNyregPerson().getOrgnr());
editPerson.setLandKod(apc.getNyregPerson().getLandKod());
editPerson.setReferens(apc.getNyregPerson().getReferens());
}
if(apc.getLatestAction().equals("Namnsokning") && apc.getLatestActionCommand().equals("search")) {
showSearch = true;
}
if(apc.getLatestAction().equals("Arendesokning") && apc.getLatestActionCommand().equals("search")) {
showSearchF = true;
}
int nbOfRelatedPersons = 0;
String relatedPersons = "";
if(editPerson.getPersonTyp().containsKey(PandoraConstants.PERSONTYP_OMBUD)) {
editOmbud = editPerson;
PersonInfoIndex pii = editOmbud.getPersonTyp().get(PandoraConstants.PERSONTYP_OMBUD);
if(pii!=null) {
nbOfRelatedPersons = pii.getRelatedPersons().size();
//Ska bara skrivas ut om inte ombudet gäller för alla sökande
if(ansokanInfo.getSokandeList().size()> nbOfRelatedPersons)
relatedPersons = pii.getRelatedPersonsAsString();
}
editPerson = new PersonInfo();
}
int vectr = 0; // får bara användas i errormessages.jspf
IFormData ifData = sessionData.getFormData();
%>
<body id="content" onload="if(document.getElementById('beroende') != null) { ingVar(document.getElementById('beroende').value); }">
<br><br>Sök person/<br>företag:<br>
<input type="button" value="Sök" onClick="document.getElementById('popupF').style.display='';">
<div class="popup" id="popupF"
<% if(!showSearchF) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/fullfoljd_fran_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupSokNamn2"
<% if(!showSearch2) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/namnuppgifter_sok2.jspf" %>
</div></div></div>
<div class="popup" id="popupSokNamn"
<% if(!showSearch) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/namnuppgifter_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupD"
<% if(!showSearchD) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/handlaggare_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupI"
<% if(!showSearchI) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/ingivningsdag_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupP"
<% if(!showSearchP) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/prioriteter_sok.jspf" %>
</div></div></div>
<div class="popup" id="popupR"
<% if(!showSearchR) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/rabattgrundande_sok.jspf" %>
</div></div></div>
</form>
<%# include file="WEB-INF/jspf/arendeprocess_messages_inc.jspf" %>
<p> </p><p> </p><p> </p><p> </p>
</body>
</html>
And when I add this part it starts complaining about pagecontext:
<div class="popup" id="popupF"
<% if(!showSearchF) { %>
style="display: none;"
<% } %>
>
<%# include file="WEB-INF/jspf/fullfoljd_fran_sok.jspf" %>
</div>
I don't even have JSP code in the popup, I reduced it to plain HTML to prove that it is not my JSP that is causing this error:
<table width="100%" border="1" cellspacing="0" cellpadding="2" align="center" class="TB_nb">
<tr>
<td colspan="3" class="pusher TB_nb"><h2>Sök efter ärende</h2>
</td>
<td>X</td>
</tr>
</table>
<br><br>
<h2 class="pusher">Sök efter ärende</h2>
<div id="FVsok">
<div style="text-align: right; width: 100%; padding-right: 5%; padding-top: 5px;">
<span onClick="getElementById('FsokF').style.display='', getElementById('FbottomA').style.display='none', getElementById('FbottomV').style.display='', getElementById('FVsok').style.display='none'" class="link_sm">Visa sökformulär</span>
</div>
</div>
<div id="FsokF">
<div style="text-align: right; width: 100%; padding-right: 5%; padding-top: 5px;; padding-bottom: 5px;">
<span onClick="getElementById('FsokF').style.display='none', getElementById('FbottomA').style.display='none', getElementById('FbottomV').style.display='', getElementById('FVsok').style.display=''" class="link_sm">Dölj sökformulär</span>
</div>
<div style="width: 100%; margin-left: 15px; margin-right: 80px;" class="fontS80">
<div class="fl30"> Sök efter ärende</div><div class="clear"></div>
<div class="fl30"><input type="text" size="60" name=""></div>
<div class="clear"></div>
<div class="fl30"><input type="button" value="Avbryt"></div>
<div class="fl10"><input type="button" value=" Sök " onclick="javascript:doSubmit('Arendesokning', 'search')"></div>
<div class="clear"> </div>
</div>
</div>
<div style="width: 100%; margin-left: 15px; margin-right: 15px;">
<table width="100%" border="0" cellspacing="0" cellpadding="4" align="center">
<tr>
<td><h3>Sökresultat:</h3></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td colspan="4">En massa text <span class="link">Hjälp!</span> </td>
</tr>
<tr>
<td><input type="button" value="Visa alla"></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr class="smallb">
<td>Antal ärenden: <%= resultList.size() %></td>
<td> </td>
<td>Visa ärenden: <a class="link" href="javascript:doSubmit('MenyNavigation', 'REW_<%= thisPage %>')" >
</a>
<a class="link" href="javascript:doSubmit('MenyNavigation', 'FWD_<%= thisPage %>')" >
</a> </td>
<td> </td>
</tr>
</table>
<table width="100%" cellspacing="0" align="center" class="sortable" id="unique_id">
<tr>
<th class="thkant">Ärende</th>
<th class="thkant">Ingivningsdag</th>
<th class="thkant">Sökande1</th>
<th class="thkant">Uppfinnare1</th>
<th class="thkant">Ombud1</th><!--
<th class="thkant">Region</th>
<th class="thkant">Land</th>
<th class="thkant">Telefonnummer</th>-->
</tr>
<tr class="g2" onmouseover="javascript:setStoreStyle(this)"; onmouseout="javascript:getStoreStyle(this)" <%}else{%>class="g1" onmouseover="javascript:setStoreStyle(this)" onmouseout="javascript:getStoreStyle(this)"<%} %> onclick="javascript:goToOversikt('','','','','','')" style="cursor:pointer;">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
<div id="FbottomV">
<table width="100%" align="center">
<tr>
<td align="left"><input type="button" id="visaknapp" value="Visa" disabled style="width:150px;" onClick="getElementById('sokR').style.display='', getElementById('bottomA').style.display='', getElementById('bottomV').style.display='none', getElementById('Vsok').style.display='', getElementById('sokF').style.display='none'"></td>
<td align="right"><input type="button" value="Avbryt" style="width:150px;" class="checkmargin"><input type="button" value="Infoga" disabled style="width:150px;"></td>
</tr>
</table>
</div>
<div id="FbottomA" style="display: none">
<table width="100%" align="center">
<tr>
<td align="left"><input type="button" value="Ändra i register" style="width:150px;"></td>
<td align="right"><input type="button" value="Avbryt" style="width:150px;" class="checkmargin"><input type="button" value="Infoga" style="width:150px;"></td>
</tr>
</table>
</div>
I think this is because of having scriplets in your JSP. You might have some scriptlet which is not closing the block properly.
Or could be some of your jspf's are is not having proper braces. Look at your generated Java code and debug where it has gone wrong.
Using Java code inside JSP should be avoided to get rid of these kind of problems. Java code should be put in Sevlets and EL should be used in JSP's.
How can I access the values in the textBox to pass it into a SQL database. What will be the text-box's unique name in each row?
The code is as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%# page import="java.sql.*" %>
<%# page import="java.io.*" %>
<html>
<head><title>orderSample</title>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function() {
$('.add').click(function() {
$(this).closest('tr').find('.quantity').attr('disabled', !this.checked);
});
});
</script>
</head>
<body bgcolor="white">
<form method=post name=orderForm>
<h1>Data from the table 'item details' of database 'caffe' in sql </h1>
<%
System.out.println("adadadasasasasasasasasas");
int i = 0;
%>
<TABLE cellpadding="15" border="1" style="background-color: #ffffcc;">
<TR>
<TD>ORDER ID</TD>
<TD>ORDER PRICE</TD>
<TD>Quantity</TD>
<TD>Add Item</TD>
</TR>
<%do{
System.out.println("I am in Ob");
%>
<TR>
<TD>asdadsas</TD>
<TD>asdasdasd</TD>
<td><input type="checkbox" class="add" /></td>
<td><input type="text" class="quantity" /></td>
<!-- <td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" IsEnabled="{Binding ElementName=checkBox1, Path=IsChecked}"/></td>
<td><INPUT TYPE="TEXT" NAME="NAME_TEXT<%=i%>" VALUE="" /></td>
<td><input type="checkbox" name="others<%=i%>" onclick="enable_text(this.checked,<%=i%>)" ></td>-->
</TR>
<%i++; }while(i<2); %>
</TABLE>
</form>
</body>
</html>
Either give them all the same name
<td><input type="text" name="name" /></td>
so that you can use
String[] values = request.getParameterValues("name");
Or give them all the same prefix
<td><input type="text" name="name${someDynamicValue}" /></td>
so that you can use
for (Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
if (entry.getKey().startsWith("name")) {
String value = entry.getValue()[0];
// Add to list?
}
}
Or when it is an incremental suffix
<td><input type="text" name="name${index}" /></td>
then use
for (int i = 0; i < Integer.MAX_VALUE; i++) {
String value = request.getParameter("name" + i);
if (value == null) {
break;
}
// Add to list?
}