环境:Windows 7,NetBean 6.9(包括GlassFish v3,Java EE 6),MySQL服务器
我已经在MySQL数据库中创建了表,并通过右键单击项目并选择" create entity from database" 来使用NetBean的功能(对不起,如果措辞错误,因为我的NetBean是日语)
这将创建实体.
现在我去测试我是否可以通过实体管理器访问数据库.
Tmp.java
package local.test.tmp;
import Resources.Users;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;
/**
*
* @author m-t
*/
public class Tmp {
private static EntityManagerFactory factory;
private static final String WEB_PU = "WebApplication1PU";
public static void main(String args[]) {
factory = Persistence.createEntityManagerFactory(WEB_PU);
EntityManager em = factory.createEntityManager();
//read existing entries and write to concole
Query q = em.createQuery("select * from users");
List<Users> userList …Run Code Online (Sandbox Code Playgroud) 我正在使用JPQL Native查询来连接表并存储查询结果List<Object[]>.
public String getJoinJpqlNativeQuery() {
String final SQL_JOIN =
"SELECT v1.bitbit, v1.numnum, v1.someTime, t1.username,
t1.anotherNum FROM MasatosanTest t1
JOIN MasatoView v1 ON v1.username = t1.username;"
System.out.println("get join jpql native query is being called
============================");
EntityManager em = null;
List<Object[]> out = null;
try {
em = EmProvider.getDefaultManager();
Query query = em.createNativeQuery(SQL_JOIN);
out = query.getResultList();
System.out.println("return object ==========>" + out);
System.out.println(out.get(0));
String one = out.get(0).toString(); //LINE 77 where ClassCastException
System.out.println(one);
}
catch(Exception e) {
}
finally {
if(em …Run Code Online (Sandbox Code Playgroud) 我使用的是Visual C#Express 2010(.NET Framework 4.0),Windows 7 32位.
我创建了WinForm项目,它只有WebBrowser控件和ListItem对象,通过onclick事件显示html信息.
我的目标是运行项目并单击webbrowser控件中的网站中的文本字段,并显示已单击的html文档信息(例如文本字段标记等)
码
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private mshtml.HTMLDocument doc = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
object oUrl = "http://livemocha.com/";
object oEmpty = "";
myBrowser.Navigate(oUrl.ToString());
}
private void myBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
try
{
doc = (mshtml.HTMLDocument)myBrowser.Document.DomDocument;
mshtml.HTMLDocumentEvents2_Event iEvent = (mshtml.HTMLDocumentEvents2_Event)doc;
iEvent.onclick += new HTMLDocumentEvents2_onclickEventHandler(ClickEventHandler);
}
catch (UnauthorizedAccessException err)
{
Console.WriteLine("OOPS: " + err);
}
}
//event handler …Run Code Online (Sandbox Code Playgroud) 我有 2 个具有相同对象类型的列表。
List A [ foo, bar, moo, woo, pee ]
List B [ bar, woo ]
Run Code Online (Sandbox Code Playgroud)
我想比较这两个列表,如果名称匹配,则将其属性设置为 true。
例如,
if(ListA[1].name.equals(ListB[0].name)) { //match name 'bar' and 'bar'
ListA[1].hasSameName = true;
}
Run Code Online (Sandbox Code Playgroud)
类似的事情。
我可以写出 O(N^2) 的解决方案。
for(Talent checkedTalent : ListA) {
for(Talent filteredTalent : ListB) {
if( checkedTalent.Id.equals(filteredTalent.Id) ) {
filteredTalent.isSelected = true;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这可以以更有效的方式完成吗?
我正在阅读的所有在线参考文献和首页JSP和Servlet书都说明了RequestDispatcher和Redirect(即resoponse.sendRedirect())的特性,如:
"请求调度程序" - 浏览器栏中的URL不会更改.
"重定向" - 用户在浏览器中看到新URL.
但根据我的测试,对于RequestDispatcher,我看到URL发生了变化,所以我不明白它们的真正含义.
使用下面的代码,
我在http://whatever.com/tmp3.jsp,这就是浏览器中的URL所说的.
单击按钮调用servlet,然后将数据转发给服务器,然后服务器将响应发送回浏览器,因此浏览器中的URL现在显示 http://whatever.com/register
所以.. URL改了!(从.../tmp3.jsp到... /注册)
任何人都可以向我解释"浏览器中的URL不会改变"的含义吗?
例:
(tmp3.jsp)
<html>
<head>
</head>
<body>
${message}
<!-- click button to send request to servlet -->
<form method="POST" action="register">
<input type="submit" value="click!">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
(servlet的)
package com.masatosan.tmp;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Tmp extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse …Run Code Online (Sandbox Code Playgroud) 我有一个函数searchWorkByName,它以"key"作为参数,并使用SQOL来检索数据.
在visualforce方面,我有一个调用searchWorkByName的链接,但希望能够传递诸如字符'a'之类的参数
例如,(这会引发错误)
<apex:commandLink value="search!" action="{!searchWorkByName('aaa')}" />
Run Code Online (Sandbox Code Playgroud)
如果没有替代方案,是否可以这样做?
顶级课程
public class SearchWorkTest {
public PageReference searchWorkByName(String key) {
//find record of work names starting from provided key character
workNames = [select name from work__c where work__c.name like 'key%'];
return Page.searchResult;
}
}
Run Code Online (Sandbox Code Playgroud)
visualforce
<apex:page standardController="work__c" extenstions="SearchWorkTest">
<!-- Is it possible to pass argument like 'foo' ? -->
<apex:commandLink value="search!" action="{!searchWorkByName}" />
</apex:page>
Run Code Online (Sandbox Code Playgroud) 可以显示下载弹出对话框
window.location = "someUrl"
Run Code Online (Sandbox Code Playgroud)
或者只是简单地有一个发送HTTP GET方法的链接等等.我成功完成了这个.
但现在我想用HTTP POST做Ajax.POST主体有JSON之类的
{"val1":"key1", "val2":"key2"}
Run Code Online (Sandbox Code Playgroud)
然后在servlet端,它读取JSON并对DB执行查询以获取数据,然后根据查询数据生成Excel.
我不能让它工作的部分是客户端.
假设我的servlet resources/report/schedule生成Excel文件.
使用Ajax时,这不会弹出下载对话框:(任何人都可以帮我如何使用Ajax下载对话框?
function post25() {
var jsonInput = {};
jsonInput['??????'] = "481";
jsonInput['?????'] = "11";
jsonInput['???'] = "2000/01/01";
jsonInput = JSON.stringify(jsonInput);
var ajaxRequest = new XMLHttpRequest();
ajaxRequest.onreadystatechange = function() {
if(ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
var res = ajaxRequest.responseText;
//location.href = "../resources/report/schedule";
}
else if(ajaxRequest.status == 409 || ajaxRequest.status == 500 || ajaxRequest.status == 204) {
alert(ajaxRequest.status);
document.getElementById("showMessage").innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("POST", …Run Code Online (Sandbox Code Playgroud) 我星期一有一个日历.
2011年5月
----------------------------
Mon Tue Wed Thu Fri Sat Sun
----------------------------
25 26 27 28 29 30 1 week 1
2 3 4 5 6 7 8 week 2
9 10 11 12 13 14 15 week 3
16 17 18 19 20 21 22 week 4
23 24 25 26 27 28 29 week 5
30 31 1 2 3 4 5 week 6
Run Code Online (Sandbox Code Playgroud)
我想找一个月的日期.
以下在星期日开始的日历上工作正常.
function getWeekOfMonth(date) {
prefixes = ['1', '2', '3', '4', '5'];
return prefixes[0 | …Run Code Online (Sandbox Code Playgroud) 我正在使用.NET 2.0 Visual Studio 2005 C#.
下面的代码从包含书签.url文件的目录中获取IE收藏夹(书签)的文件名
例
../users/favorites/blah.url
但我真正想要的是该文件中的书签URL.
检查文件属性时,在Web文档选项卡中显示文件名和URL.
如何从C#访问它?
码
//the code below just get String like "..../users/favorites/blah.url"
//call the method with the folder path:
//GetFavoriteFiles(Environment.GetFolderPath(Environment.SpecialFolder.Favorites));
private List<String> favFiles = new List<String>();
private void GetFavoriteFiles(String folder)
{
String[] favs = Directory.GetFiles(folder);
favFiles.AddRange(favs);
String[] folders = Directory.GetDirectories(folder);
if(folders != null)
{
foreach(String s in folders)
{
GetFavoriteFiles(s);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我的应用程序行为异常,并认为下面的代码意外地发出了其他声明.
码
if(" " != 0) {
console.log("whitespace is not zero");
}
else {
console.log("bar");
}
Run Code Online (Sandbox Code Playgroud)
Firebug输出
bar
Run Code Online (Sandbox Code Playgroud)
我认为空格是一个字符串,与整数零的比较应该像上面的情况一样返回false,但我不知道为什么它会转到else语句.
谁有人解释为什么?
java ×5
.net ×2
c# ×2
javascript ×2
jpa ×2
servlets ×2
ajax ×1
algorithm ×1
arguments ×1
download ×1
favorites ×1
jpql ×1
jsp ×1
list ×1
netbeans-6.9 ×1
salesforce ×1
sql ×1
url ×1
visualforce ×1
whitespace ×1