I've writen a servlet that builds an html page showing the content of a database. The code is:
Statement st = (Statement) conexion.createStatement();
ResultSet rs = st.executeQuery("select * from audiolist" );
while (rs.next())
{
contador++;
out.println("<tr>");
String k = rs.getString("Tittle");
String l = rs.getString("Autor");
String m = rs.getString("Album");
out.println("<td>"+"<input type=\"radio\" name=\"titulo<%="+contador+"%>\"value=\""+k+"\">");
out.println("<td>" + k + "</td>");
out.println("<td>" + l + "</td>");
out.println("<td>" + m + "</td>");
out.println("</tr>");
}
out.println("</table></center>");
out.println("<tr><td colspan=2><input type=submit></td></tr>");
out.println("</form>");
I've added a radio button to each row. With this code I get to show in the browser a table with the content of the database. When I click on submit I want send to another servlet the vale 'k' for the row selected. I'm having a hard time with this. I think I'm sending the value incorrectly. In the second servlet, is it enough to use getParameter() in order to get the info?
Thanks!
In the second servlet you can use:
String value = request.getParameter("tituloX");
to read the value. You need to know the name of the parameter to do. If this is not known, you can try to enumerate the parameters:
for ( Enumeration e = request.getParameterNames(); e.hasMoreElements();) {
String param = (String) e.nextElement();
String value = request.getParameter(param );
}
This only works for parameters with a single value.
Is this line correct?
out.println("<td>"+"<input type=\"radio\" name=\"titulo<%="+contador+"%>\"value=\""+k+"\">");
Related
A co-worker of mine shared an autohotkey script (it's actually an exe file that runs on the background). Anyways, when I click the hotkeys it opens up a company webiste and creates a shared query for whatever's on the clipboard. I was wondering how this is done and how I can make my own.
I'm specially curious about the "URL" modification that includes all these search options:
https://<COMPANYWEBSITE>/GotoDocumentSearch.do
That's the URL where I can search (sorry it's restricted and even if I link it you cant access it).
Anyways, after I set up all my options and stuff and click the search button I get the following URL:
https://<COMPANYWEBSITE>/DocumentSearch.do
I inspected the website source and this is the function that's called when I press the search button:
function preSubmitSearch(docPress) {
document.pressed = docPress;
// setup local doc types for submit by lopping over multi selects and building json data string
var localDocTypesJson = "{";
var sep = "";
jQuery(".localTypeSel").each(function (i) {
var selLocalTypes = jQuery(this).multiselect("getChecked");
// get doc type code from id ex. 'localTypeSel_PD'
//window.console.log("this.id=" + this.id);
var tmpArr = this.id.split("_");
var docTypeCode = tmpArr[1];
var selLocalTypesCnt = selLocalTypes.length;
if (selLocalTypesCnt > 0) {
var localTypes = "";
var sep2 = "";
for (var i2 = 0; i2 < selLocalTypesCnt; i2++) {
localTypes += sep2 + "\"" + selLocalTypes[i2].value + "\"";
sep2 = ",";
}
localDocTypesJson += sep + "\"" + docTypeCode + "\": [" + localTypes + "]";
sep = ",";
}
});
localDocTypesJson += "}";
jQuery("#localDocTypesJson").val(localDocTypesJson);
}
HOWEVER, the working code that was shared with me (that was written ages ago by some employee who's not here anymore). Has the following URL when I use the autohotkey:
https://<COMPANYWEBSITE>/DocumentSearch.do?searchType=all&localDocTypesJson=7D&formAction=search&formInitialized=true&searchResultsView=default&btn_search=Search&docName=*<CLIPBOARD>*&wildcards=on&docRevision=&latestRevOnly=true&docProjectNumber=&docEngChangeOrder=&docLocation=&findLimit=500&docTypes=Customer+Drawing&docTypes=Production+Drawing&docTypes=Manufacturing+Process+Document&docTypes=Specification+Or+Standard
Note: replaced text with "CLIPBOARD" for clarification.
I was wondering if that's a type of "URL-programming" or how can I make a direct URL that prompts for the search results from the website? is that Javascript? or how is that programmed? (I know Swift and some Java, but have never really used Javascript).
It doesn't seem like you are asking an AutoHotKey (AHK) question, but to give you an AHK example you can copy, here is how I would use AHK to use Google.com to search for whatever is in my clipboard:
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate("https://www.google.com/search?q=" . StrReplace(Clipboard, " ", "+") . "", "")
Note, the URL format includes the query ("?q=whatever+you+had+in+Clipboard") in it with spaces replaced by "+"s.
Hth,
I am trying to automate my businesses blog. I want to create a dynamic html string to use as a wordpress blog description. I am pulling text data from email body's in my gmail account to use as information. I parse the email body using the first function below.
I have everything working properly except for the for loop (in the second code block) creating the description of the post. I have searched for hours and tried dozens of different techniques but I cant figure it out for the life of me.
Here is how I am reading the text values into an array:
function getMatches(string, regex, index) {
index || (index = 1); // default to the first capturing group
var matches = [];
var match;
while (match = regex.exec(string)) {
matches.push(match[index]);
}
return matches;
}
This is how I am trying to dynamically output the text arrays to create a basic HTML blogpost description (which I pass to xmlrpc to post):
var1 = getMatches(string, regex expression, 1);
var2 = getMatches(string, regex expression, 1);
var3 = getMatches(string, regex expression, 1);
var3 = getMatches(string, regex expression, 1);
var fulldesc = "<center>";
var text = "";
for (var k=0; k<var1.length; k++) {
text = "<u><b>Var 1:</u></b> " + var1[k] + ", <u><b>Var 2:</u></b> " + var2[k] + ", <u><b>Var 3:</u></b> " + var3[k] + ", <u><b>Var 4:</u></b> " + var4[k] + ", <br><br>";
fulldesc += text;
}
fulldesc += "</center>";
Lastly here is the blog post description code (using GAS XMLRPC library):
var fullBlog = "<b><u>Headline:</u> " + sub + "</b><br><br>" + fulldesc + "<br><br>General Description: " + desc;
var blogPost = {
post_type: 'post',
post_status: 'publish', // Set to draft or publish
title: 'Ticker: ' + sub, //sub is from gmail subject and works fine
categories: cat, //cat is defined elsewhere and works fine
date_created_gmt: pubdate2, //defined elsewhere (not working but thats another topic)
mt_allow_comments: 'closed',
description: fullBlog
};
request.addParam(blogPost);
If there's only one value in the var1,2,3,4 arrays all works as it should. But any more than 1 value and I get no output at all from the "fulldesc" var. All other text variables work as they should and the blog still gets posted (just minus some very important information). I'm pretty sure the problem lies in my for loop which adds the HTML description to text var.
Any suggestions would be greatly appreciated, I'm burned out trying to get the answer! I am a self taught programmer (just from reading this forum) so please go easy on me if I missed something stupid :)
Figured it out: It wasnt the html/text loop at all. My blogpost title had to be a variable or text, but not both.
Not working:
title: 'Ticker: ' + sub, //sub is from gmail subject and works fine
Working:
var test = 'Ticker: ' + sub;
//
title:test,
I have to get a cell's value from a DataGrid, but i get exception when i try to use TbRogDatum.Text = Convert.ToString(((DataRowView)DgUjMegrendeles.SelectedItem).Row["MEGRENDEL"]); this code i get an "ArgumentException" exc. with "Additional information: The „MEGRENDEL” column is not included to the 'beszallitoi_megrendeles' table."
I am using mysql query to fill the DataGrid, and the query contains the DATE_FORMAT(Vmegrendeles_datuma, \"%Y-%m-%d\") as 'MEGRENDEL' column. Any idea what to do? (btw i could get the cells value anytime this way but here it doesnt work)
EDIT:
Here is the DataGrid binding:
string q = "Select azonosito as 'AZ', DATE_FORMAT(Vmegrendeles_datuma, \"%Y-%m-%d\") as MEGRENDEL, DATE_FORMAT(KertSzDatum, \"%Y-%m-%d\") as 'KERTSZDATUM', vevo_csoport As VEVO_CSOPORT,"
+ " rovidvevonev AS 'ROVIDVEVONEV',gyarto AS 'GYARTO',megnevezes AS 'MEGNEVEZES', darab AS 'DARAB'," +
"megjegyzes AS 'MEGJEGYZES' ,vrendelesiazonosito as 'RENDSZAM',brendelesiazonosito As BRENDSZAM,rogzito_neve AS ROGNEV,beszallito AS BESZALLITO," +
"DATE_FORMAT(megrendeles_datuma, \"%Y-%m-%d\") AS MEGREND,DATE_FORMAT(varhato_erkezes, \"%Y-%m-%d\") AS VARERK,csomagkuldo_ceg AS CSKULD,megjegyzes2 AS MEGJEGY2," +
"megrendelt AS BMEGREND,DATE_FORMAT(beerkezes_datuma, \"%Y-%m-%d\") As 'BERKDAT', beerkezett as 'BEERK' from `beszallitoi_megrendeles` "
+ " where megrendelt='1' and beerkezett='0' order by megrendeles_datuma desc;";
parancs = new MySqlCommand(q, Kapcsolat);
Kapcsolat.Open();
parancs.ExecuteNonQuery();
Kapcsolat.Close();
MySqlDataAdapter mda = new MySqlDataAdapter(parancs);
DataTable dt = new DataTable("beszallitoi_megrendeles");
mda.Fill(dt);
DgUjMegrendeles.ItemsSource = dt.DefaultView;
mda.Update(dt);
and the xaml:
<DataGridTextColumn Width="80" Binding="{Binding MEGRENDEL,StringFormat={}{0:MM/dd}}" IsReadOnly="True"/>
I'm starting to learn servlet and I'm using MySQL and Tomcat. I'm trying to make a simple servlet that when the submit button is clicked it will display a different set of instruction by calling the doGet() function again and moves the cursor to the next set.
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
{
out.println("<HTML><HEAD><TITLE>Instructions</TITLE><HEAD>");
out.println("<BODY>");
ResultSet rs = stmt.executeQuery("SELECT InstructNo, Instruct FROM Intructions");
if(rs.next())
{
out.println(rs.getString("InstructNo") + ". " + rs.getString("Instruct"));
}
out.println("<form method=\"get\" action=\"\">");
out.println("<input type=\"radio\" name=\"ans\" value=\"true\">True<br>");
out.println("<input type=\"radio\" name=\"ans\" value=\"true\">False<br>");
out.println("<input type=\"submit\" value=\"Submit\">");
out.println("</BODY></HTML>");
I can't figure out how to move the cursor to the next set when submit button is clicked and
call the doGet() function gets called again.
First you need store something that lets you know where you are in the list. So, for example, add a hidden form field with some sort of value that lets you read the right thing from your database. I'll assume your records in the db are numbered.
out.println("<input type=\"radio\" name=\"ans\" value=\"true\">False<br>");
out.println("<input type='hidden' name='index' value='" + index + "' />");
out.println("<input type=\"submit\" value=\"Submit\">");
Then you need to collect the that value when the server gets the request and use it to read the next value:
String index = req.getParameter("index");
int idx = Integer.parseInt(index); // add code to detect an exception here
ResultSet rs = stmt.executeQuery("SELECT InstructNo, Instruct FROM Intructions where Index=" + index); // Check my rusty SQL here
Then figure out the next one:
index = "" + (idx+1); // The +1 means to get the next one next time
out.println("<form method=\"get\" action=\"\">");
What about replacing the if statement with a while loop for iterating over all the records in the database and then you can use the same code to print it to the web page.
You may also want to learn about using JSPs which makes the separation between the controller (the servlet) and the view (the web page presented to the user; or the JSP).
I have knowledge on how to customize the display data using Struts2 displaytag:table and decorator.
But I need to customize the table columns (tr style)
public String getWorkFlow() {
WorkOrderDO currentWorkOrder = (WorkOrderDO) getCurrentRowObject();
String output = null;
if (currentWorkOrder.getChildId() == 0) {
if (!currentWorkOrder.isWorkFlowRetrieved()) {
output = "<input type = 'submit' value = 'Work Flow' id=" + currentWorkOrder.getMoveWorkOrderId() + " onclick = 'changeWorkOrder(this);return false;'/>";
} else {
output = "<input type = 'submit' value = 'Work Flow' id=" + currentWorkOrder.getMoveWorkOrderId() + " onclick = 'changeWorkOrder(this);return false;' disabled/>";
}
}
return output;
}
from above method in decorator class, we can customize the data look and feel.
But my question is, if currentWorkOrder.isWorkFlowRetrieved() == true, I want to highlight the entire column (tr) in the table in the display page with style property
Any idea?
you can do this by using style attribute in the display:column tag
for eg
I hope this works for you.