<Table>
<tr>
<td>ID</td>
<td>NAME</td>
<td>MARKS</td>
<td>Grade</td>
<td><a href="AddRecord.jsp" >Update Record</a> </td>
</tr>
</Table>
How can I get table contents for modification, when I press Update hyperlink button? or how can I send these contents as a parameter to the page "AddRecord.asp".
If you are trying to submit a new row to a data table it sounds to me like you just need to use a traditional <form> and make the "Update Record" a submit type button. You are going to have to read up on using databases and JSP to process your update requests.
I suggest you start by reading on submitting forms at: http://www.w3schools.com/tags/att_form_action.asp
I think your best best is AJAX and JavaScript. Make an AJAX call to get the content and add it to the DOM using JavaScript.
Related
I have a jsp that gathers data from the user and passes that data to a servlet. The servlet uses that data to query an api and the response is a string object that contains csv data, which is forwarded to a search results jsp page.
In the search results jsp page I call the object. It's just a string of csv values and it looks bad on the page. I'm a total novice when it comes to web app development. Any idea the best way to parse the csv data in such a way that it looks better? Maybe into a HTML table? All I can find is info on parsing through a csv file, not an object with csv data in it.
I'm sure there's a simple way to handle this but after a whole day of combing the internet I need a little help where to look...
-----Edited to add sample data.
The data is returned to the jsp like so.
product_nbr,member_nbr,prod_cd,create_dt XYZ0000,000,777,2015-10-30
The first 4 fields are the headers and the data follows in line. I would like it to look like this..
(stackoverflow doesn't allow the table tag, but you really I just want to be able to display an HTML table on screen)
<table>
<tr>
<td>product_nbr</td>
<td>member_nbr</td>
<td>prod_cd</td>
<td>create_dt</td>
</tr>
<tr>
<td>XYZ0000</td>
<td>000</td>
<td>777</td>
<td>777</td>
</tr>
</table>
I recommend you to read this article:
http://www.journaldev.com/2090/jstl-tutorial-with-examples-jstl-core-tags
It shows you how to use JSTL in a JSP. You have to use the forEach tag like this, but before yoy have to parse your csv file into a array.
http://www.tutorialspoint.com/java/java_string_split.htm
String a = "product_nbr,member_nbr,prod_cd,create_dt XYZ0000,000,777,2015-10-30";
String[] b = a.split(",");
Este es un JSP de ejemplo
<table>
<tbody>
<tr><th>ID</th><th>Name</th><th>Role</th></tr>
<c:forEach items="${requestScope.empList}" var="emp">
<tr><td><c:out value="${emp.id}"></c:out></td>
<td><c:out value="${emp.name}"></c:out></td>
<td><c:out value="${emp.role}"></c:out></td></tr>
</c:forEach>
</tbody>
</table>
I am developing a Sprin MVC application and I have a form containing a table in one of the UI jsp's, (welcome.jsp) and when the submit button is clicked, I am trying to print out the data in the form to the web applications console.From there i intend to parse the checkboxes that are selected and then have the controller send the 'selected' data back to the databased to be updated to the next status in the applications flow.
So far the form is 'successfully' posting as in no error or exceptions is being thrown, but the printed statement in the console is blank which makes me think that no data is being sent, and I would greatly welcome any help to fix this.
Here is the setup of what I have, not the actual code but a rough set up of the elements and methods.
welcome.jsp:
<form action="<c:url value="/postPage" />"method="post" modelAttribute="rTable">
<br/>
<table>
<thead>
<tr>
<th>title1</th>
<th>title2</th>
<th>title3</th>
<th><select>
<option>option1</option>
<option>option2</option>
</select></th>
</tr>
</thead>
<tbody>
<tr>
<td>value1</td>
<td>value1</td>
<td>value1</td>
<td><input type="checkbox" value="row_data_id" /></td>
</tr>
</tbody>
<tfoot>
<tr><td colspan="4"></td>
</tfoot>
</table>
<br/>
</form>
My controller has the following method in it with all the necessary libraries imported:
controller.java
#RequestMapping(value="/postPage", method = RequestMethod.POST)
public String processUpdate(#ModelAttribute("rTable") String table, ModelMap model) {
System.out.println(table);
return "postPage";
}
The console line that is print is this:
.
.
.
[3/19/14 16:36:53:625 EDT] 0000006a SystemOut O
.
.
.
Does anyone know why this is not printing anything? Am I really not successfully sending anything to the controller?
After a good deal of reading and trial and error I found my answer. I will explain in terms with spring framework forms. In order to pass data through the form from front-end to back end, first every input will need to be tied to the form using the spring form JSTL tag
ex.
form => form:form
input=> form:input
in the form:form it isn;t necessary but you should have a modelAttribute that is linked to a java class, then in each input their need to be a path attribute the is linked to a variable in the modelAttribute class and a value to assign to the variable. Then on a submit the values are linked to the back end via the getters and setters on the java class to be used in the back-end. I hope I am explained that clearly.
How is it possible to refresh the data which i get from the servlet in the jsp page without refreshing the whole page.
I am not satisfied with my solution now, which is:
polling a jsp page from the server and loading it in a div container. (See following)
My jsp file would look like following:
<c:forEach items="${list}" var="myList" >
<tr>
<td class="aligncenter">
<span class="center">
<input type="checkbox" name="option${myList.id}" value="${myList.id}"></input>
</span></td>
<td class="listId">${list.id}</td>
<td>${myList.title}</td>
<td>${myList.description}</td>
<td style="text-align:center;"><img style="height:40px;" src="../../app/images/food/thumbnail/${myList.imagePath}"></img></td>
</tr>
</c:forEach>
Know i have a method which calls a method in my controller that retrieves a this jsp file with the attributes in the model.
Then I load this jspfile in a div with jquery
jQuery('.myDivWhereIWantToLoadMyJspFile').load(data);
Is there a other possibility to refresh the data in a jsp page except websockets?
This is possible using an Ajax request, that is meant to be used for partial page refreshes. With ajax a request is sent to the server but the page remains the same.
Then an event is triggered when the response arrives. In response to that event we can modify parts of the page with fresh data without reloading it.
See this answer for an example of how to do it with jQuery.
The index page of the site will ask user to select a stage area. I want to pass their selection from page to page until they log out or return to this selection.
I have searched long and hard but just don't know how to phrase that question to a web search. Just need a little push in the right direction. Form code below and thanks in advance.
<form name="pick" method="POST" action="http://wavepick.htm">
<table border="0">
<tr VALIGN="TOP">
<td width="177">
<select id="stageChoice" name="stageArea">
<option selected value=" ">(Select Staging Area)</option>
<option value="A">A </option>
<option value="B">B </option>
</select>
</div>
<input type="submit" name="Submit" value="Stage" name="B1">
<input type="hidden" name="request_id" value="wavepick">
</form>
You can store the selected value between pages in a session variable.
If you want to do this only with HMTL/Javascript, you have to submit this form via "GET" (instead "POST"), and at each page you need to send again "stageArea" to the another page, so:
Page1.html?stageArea=B
Page2.html?stageArea=B
Page3.html?stageArea=B
That's how you read GET parameters via Javascript: How can I get query string values in JavaScript?
Ya, it's very arduous just with HTML/Javscript.
But you have mentioned "log out", do you have back-end (like PHP, ASP.NET,etc..)? With back-end language it'll be much more easier, you could store stageArea on session once, and just read it at each page.
If you are using a backend language such as PHP you can store that value in a $_SESSION variable. and access it wherever you need during that session.
Here is the documentation for the session variables:
PHP Session
If not, let me know and i'll figure out a different method for you.
Given the following,
<logic:notEqual name="ABCForm" property="externalFactor" value="true">
<tr>
<td width="20%" class="label" height="14"><bean:message key="factorDefault"/></td>
<td class="label">
<html:radio property="defaultState" value="Y"><bean:message key="Yes"/></html:radio>
<html:radio property="defaultState" value="N"><bean:message key="No"/></html:radio>
</td>
</tr>
</logic:notEqual>
How do I hide this row on the page at all times without deleting data associated with this row in the database?
I tried replacing logic:notEqual with logic:empty and the jsp is blank for that div. I have tried simply removing this entire block of code, and of course that works. I am just concerned if that affects the database, or if there any pages that rely on data associated with the code snippet.
Mr.gabybaby you do one thing...
in your database table you add another column like status
by default status value is active if any user wants to delete any record through your JSP just you change that record status=inactive..
you should display only active records in jsp...
i think this is the solution for your requirement