I have a string:
Am trying to do the below :
int i =0;
for(String s : appFields){
i++;
String divid = "chart_"+i;
divid = divid.replaceAll("[\\r\\n]+$", "");
}
I would like to trim it so that the value is only chart_1 and so on.
Can someone help me please?
<%
String[] appFields = "Account Information,Action Status,Activity Name,Activity Status,Last Activity Timestamp,Geographical Region,Enterprise Status,Business Process,Numer of Pages,Message Direction".split(",");
int i =0;
for(String s : appFields){
i++;
String divid = "chart_"+i;
divid = divid.replaceAll("[\\r\\n]+$", "");
%>
<tr>
<td><% out.println(i); %></td>
<td><% out.println(s); %></td>
<td class='with-3d-shadow with-transitions'><p><svg id="<% out.println(divid); %>" class="sparkline"></svg></p></td>
</tr>
<%
}
%>
This is the output i get in Chrome Web Inspector
<td class="with-3d-shadow with-transitions"><p><svg id="chart_1
" class="sparkline"></svg></p></td>
temp = temp.trim();
Strings are immutable so operations return new Strings that you have to assign back to the original reference variable.
Change your line to
<svg id="<%out.print(divid);%> " class="sparkline"></svg>
In other words, use print instead of println. println adds a new line after your String.
Related
I am assigning an integer converted into string value to a hidden input through a loop where s1 is the loop iterator.
<% int k=0;
String s1 = null;
while(mar.next()){
k++;
s1 = Integer.toString(k);%>
<table>
<tr><td><b>User Name </b> </td> <td><%= mar.getString("UserName") %></td></tr>
<tr><td><b>Type </b></td><td> <%= mar.getString("Type") %></td></tr>
<tr><td><b>Complain </b></td> <td><%= mar.getString("Complaint") %></td></tr>
<tr><td><b>Status </b> </td> <td><%= mar.getString("Status") %></td></tr>
<tr><td><b>Date </b> </td> <td><%= mar.getString("Date") %></td></tr>
</table>
<form action = "demo1.jsp" method = "post">
<% out.println(mar.getString("Id")); %>
<input type="radio" name = "<%= mar.getString("Id") %>"value="pending"checked>Pending
<input type="radio" name = "<%= mar.getString("Id") %>" value="done">Done
<input type="submit" name = "B" id = "submit" >
<input type = "hidden" name = "try" value = <%= s1 %> >
<% out.println(s1); %>
</form>
<br>
<br>
<%
}
Below is the code which should return a string of values from 1 to 3 (values of s1)
String[] vals;
vals = new String[3];
out.println(vals.length);
vals = request.getParameterValues("try");
out.println(vals.length);
for(int i=0; i<vals.length; i++){
out.println("Hy");
out.println(vals[i]);
}
It is only returning one value which is the first one and printing vals.length prints 1.
You are creating three forms. For each form there will be separate request made. Since each form contains only one hidden input you will always get only one value for each request for below code
request.getParameterValues("try");
Now if you have to submit all the forms with one click. here or here are the answers
I am tying to alert the value of namesEmp variable and i get this Ljava.lang.String;#3433205b as result.
my javacsript:
function getNames(names) {
var namesEmp = "";
var namesEmpText = "";
for(i=0;i<names.length;i++) {
if(names.options[i].selected) {
namesEmp = names.options[i].value;
namesEmpText = names.options[i].text;
alert(namesEmp);
alert(namesEmpText);
}
}
}
and here is my HTML:
<tr style="position:relative;left:19;top:1;display:none;">
<td style="position:relative;top:1;text-align:right;">Country:</td>
<td>
<select id="namePay" name="namesPay" onChange="setTimeout('getNames(f.name)',1);">
<%
String namesDesc = "";
if(namesList.size()>0){
for(int i=0;i<namesList.size();i++){
String[] namesValues = ((String)namesList.get(i)).split("~");
NamesText = namesValues[0];
%>
<option value="<%=namesValues%>"><%=NamesText%>
<%}
}%>
</select>
</td>
</tr>
When I alert namesEmpText, i get the the correct result. Any help would be appreciated.
The issue is here:
<option value="<%=namesValues%>"><%=NamesText%>
^
You are trying to render the Java object namesValues (a string array), as a select option value. The JVM doesn't know how to automatically convert an array to a string, so it renders the type name for it instead. Did you mean to include an indexer to that array? For example:
<option value="<%=namesValues[1]%>"><%=namesValues[0]%>
List<Object> result = (List<Object>)guestSession.Available_RoomType(startDateString, endDateString, name);
List<Roomtype> new_room;
List<? extends Object> list = result;
new_room = (List<Roomtype>) list;
%>
<table>
<%if(new_room!=null){
for(Roomtype r : new_room){%>
<tr>
<td><%= r.getName() %></td>
<td><%= r.getDescription() %></td>
<td><%= r.getPrice() %></td>
</tr>
<%}
}%>
</table><%
}
%>
new_room has size 0 when i debug it but the properties are not displaying. the compiler jumps everything in the tr. Please any reason for this because the page comes blank after.
First, please don't use scriptlets. Second,
List<Roomtype> new_room = (List<Roomtype>) guestSession.Available_RoomType(
startDateString, endDateString, name);
%>
<table>
<% if(new_room != null) {
for(Roomtype r : new_room){%>
Finally, I suggest you take a look at <c:forEach> as it supports iterating a collection.
My String is
**abcd
*[abc]
<td> **Welcome
**Welcome Again
</td>
Is their any way in which I can remove the * symbol in between the tags so that my final string string would be something like
**abcd
*[abc]
<td> Welcome
Welcome Again
</td>
Here all the * between <td> and </td> are removed
I dont want to use string.
Try this,
if (s.contains("<td>"))
{
String first = s.substring(0, s.indexOf("<td>"));
String last = s.substring(s.indexOf("<td>"), s.indexOf("</td>") + 5);
System.out.println("result : "+first + last.replace("**", ""));
}
else
{
System.out.println("result : "+s);
}
I am creating row dynamically in while loop.
As data fetched from specific directory, required row will created.
But i want to give alternate zebra color to row. fro that what i will have to do ?
Following code is on my jsp page :
<%
while(rsemail.next())
{
user_email = rsemail.getString(2);
file_name = rsemail.getString(3);
file_size = rsemail.getFloat(4);
file_type = rsemail.getString(5);
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
if(listOfFiles[i].getName().equals(file_name))
{
row_counter = row_counter + 1;
%>
<tr height="28px" id="table_row" bgcolor="#C6C6C6">
<td width="7%"><div align="center"><%= id=id+1 %></div></td>
<td width="39%"><%=listOfFiles[i].getName() %></td>
<td width="12%"><%= file_type %></td>
<td width="14%"><%= file_size/1000 %> KB</td>
<td width="14%"><div align="center">Delete</div></td>
<td width="14%"><div align="center">Download </div></td>
</tr>
<%
}
}
}
}
%>
table show directory data which can be downloaded as well as it's name & type & size also displaying.
show i want to put it up in some arranged alternate manner.
So anyone can help me ???
Did you try something like this
<%
String StrBgEven = "#C6C6C6", strBgOdd = "#FFFFFF"; // outside loop
if( i%2 == 0 ){
%>
<tr height="28px" id="table_row" bgcolor="<%=strBgEven%>">
<%
}else{
%>
<tr height="28px" id="table_row" bgcolor="<%=strBgOdd%>">
<%
}
%>
Use row count inside the loop and check if(rowcount%2==0) if, true then change the back ground color by using css.
Example :-
Loop started
<tr style="<%if(cnt%2==0){ %>background-color:#ffffff;<%}else{%>background-color:#F9F9F9;<%} %>">
</tr>
Loop End
In the above example <tr></tr> you can put your data (<td></td>).
Hope it will help you.
Put the two colors into an array colors.
Initialize an integer i to 0.
In the loop body where you iterate over the rows of the table
assign the color colors[i] to the current row
update i to the value of 1-i
To clarify this, the i in the above algorithm has to be renamed, because i is used your code already.