有没有人知道如何发送一个对象,更具体的一个List,从数据库中的查询得到的结果,到我的servlet,这是另一个Java应用程序,而不是在Google App Engine中.
更新:我在GAE中的servlet工作正常,它序列化我的List<Video>结果:
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
String titulo = req.getParameter("titulo");
String json = "";
PersistenceManager pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery("select from "+Video.class.getName()+ " where titulo.startsWith('"+titulo+"')");
List<Video> video = (List<Video>) pm.newQuery(query).execute();
json = new Gson().toJson(video);
System.out.println("SERIALIZED >> " + json);
res.setContentType("application/json");
res.setCharacterEncoding("UTF-8");
res.getWriter().write(json);
}
Run Code Online (Sandbox Code Playgroud)
我的调用servlet有这个方法:
public void receberMetaDados(String titulo) throws IOException, Exception{
InputStream input = new URL("http://localhost:8888/serve?titulo="+titulo).openStream();
Reader reader = new InputStreamReader(input, "UTF-8");
List<Video> results = new …Run Code Online (Sandbox Code Playgroud) 我想以警告用户发生的错误的方式处理我的异常.
我所知道的是:
servlet.java
private void registerUser(...){
...
try{
DAOUser daoUser = new DAOUser();
daoUser.insert(user);
catch(HibernateException he){
...
}
DAOUser.java
public void insert(User user) throws HibernateException {
...
}
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗?如果没有,你会建议什么?
此致,Valter Henrique.
我正在尝试理解以下代码:
/**
* Simple insertion sort.
* @param a an array of Comparable items.
*/
public static void insertionSort( Comparable [ ] a )
{
for( int p = 1; p < a.length; p++ )
{
Comparable tmp = a[ p ];
int j = p;
for( ; j > 0 && tmp.compareTo( a[j-1] ) < 0; j-- )
a[ j ] = a[ j - 1 ];
a[ j ] = tmp;
}
}
Run Code Online (Sandbox Code Playgroud)
但我不确定是什么意思,for( ; ) 所以我需要你的帮助.对不起,如果它是重复的,但我在这里和谷歌搜索,但到目前为止没有.
我创建了一个过滤器,它工作正常,但我的richfaces不再正常工作,这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>SuaParte</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<context-param>
<param-name>com.sun.faces.disableVersionTracking</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>LoginFilter</filter-name>
<filter-class>filter.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
我也在这里尝试@BalusC建议,将web.xml更改为:
<filter> …Run Code Online (Sandbox Code Playgroud) 我想接受这两种情况,I_LOVE_TO_CODE.txt或者I_LOVE_TO_CODE_20151125.txt.我知道如何分别为每一个做:
^I_LOVE_TO_CODE.txt$
^I_LOVE_TO_CODE_\d{8}\.txt$
Run Code Online (Sandbox Code Playgroud)
但是如何OR在单个正则表达式中插入条件?
我一直在阅读很多关于逐个功能命名约定的内容.所以我决定尝试一个新项目.但是,我不确定它应该如何命名我的大多数类将使用的包,因为我使用的是一个巨大的框架,例如Spring和Hibernate.
这是我们的Spring contexts类处理方式:
我们的database访问类,管理连接的访问类等.
我有一个关于这个的草案:使用这些框架的通用包,例如:
com.company.project.common.spring
com.company.project.common.database
Run Code Online (Sandbox Code Playgroud)
但我担心这仍然有点像package-by-layer.:) feature classes应该如何创建我将访问的包?
我可以scanf(...)用作函数的参数吗?像这样:
printInteger(scanf(....));
Run Code Online (Sandbox Code Playgroud)
我可以使用scanf将我读取的值归因于某个变量吗?像这样:
n = scanf(...);
Run Code Online (Sandbox Code Playgroud)
ps:我在这里解释为什么我这么问.
我知道这个问题可能有点奇怪,但我正在开发一个项目,它正在开发一个编译器,它将一些语言作为输入,然后编译为C.
例如,这是我的语言,我们称之为'stackoverflow';)
proc printInteger(integer k)
integer i;
begin
for i = 1 to k do
print i;
end
proc main()
integer n, i;
boolean ok;
begin
printInteger(getInteger);
n = getInteger;
ok = true;
while i < n do
begin
print i;
i = i + 1;
end
if ok then print 1; else print 0;
end
Run Code Online (Sandbox Code Playgroud)
我不会深入学习语言,但请注意,这getInteger意味着我想做一个scanf(...),我的意思是,当getInteger我想要编译时scanf(...),这就是为什么我想知道一些使用方法scanf(...).
我像这样传递我的本地环境变量:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |de|
de.vm.box = 'ubuntu/trusty64'
de.vm.hostname = 'virtual_machine'
de.vm.network 'public_network', bridge:ENV['NETWORK_INTERFACE'], ip:'192.168.2.170'
de.vm.provider "virtualbox" do |v|
v.memory = 4096
v.cpus = 2
end
de.vm.synced_folder '.', '/vagrant', disabled:true
de.vm.synced_folder '../../synced/shared/', '/shared/'
de.vm.synced_folder '../../synced/devops/', '/devops/'
install = ENV['DEVOPS_HOME'] + '/vagrant/lib/install'
de.vm.provision 'shell', path: install + '/basic'
de.vm.provision 'shell', path: install + '/java8', args: ['automatic']
de.vm.provision 'shell', path: install + '/aws_cli', args: [ENV['S3_AWS_ACCESS_KEY_ID'],ENV['S3_AWS_SECRET_ACCESS_KEY']]
setup = ENV['DEVOPS_HOME'] + '/vagrant/lib/setup'
de.vm.provision 'shell', path: …Run Code Online (Sandbox Code Playgroud) 我几乎同时运行这个PowerShell脚本两次:
#Provision Resource Group and all Resources within ARM Template
New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupName `
-TemplateFile $TemplateFile `
-Mode Incremental `
-TemplateParameterFile $TemplateParametersFile @ExtraParameters `
-keyVaultAccessPolicies @($keyVaultPoliciesList) `
-Force
Run Code Online (Sandbox Code Playgroud)
这引发了这个异常:
VERBOSE: 16:48:48 - Template is valid.
New-AzureRmResourceGroupDeployment : Unable to edit or replace deployment 'DeploymentTemplate': previous deployment from '5/18/2017 2:48:47 PM' is still active (expiration time is '5/25/2017 2:48:46 PM'). Please see https://aka.ms/arm-deploy for usage details.
At L:\Source\Start-ArmEnvironmentProvisioning.ps1:274 char:1
+ New-AzureRmResourceGroupDeployment -ResourceGroupName $ResourceGroupN ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) …Run Code Online (Sandbox Code Playgroud) 假设我有以下功能:
function Get-DBStatus
{
<# .. removed help section for brevity .. #>
[CmdletBinding()]
[OutputType([System.Object])]
param
(
[Parameter(Mandatory = $true)]
[String]$ServerName,
[Parameter(Mandatory = $true)]
[String]$ServerUser,
[Parameter(Mandatory = $true)]
[String]$ServerPassword,
[Parameter(Mandatory = $true)]
[String]$DatabaseName,
)
try
{
$params = @{ ... } # <<< It's possible to avoid this duplication ?
$dbStatus = Invoke-SqlConnection @params
}
catch
{
Write-Error -Message ('An error has occured while ...')
}
...
Run Code Online (Sandbox Code Playgroud)
@params一旦我的参数已经被声明和设置,我想避免声明.使用Powershell可以做到这一点吗?