我知道聚合和组合之间的概念差异.有人可以通过示例告诉我它们之间Java的实现差异吗?
我想将一个序列化对象从Java类发送到servlet应该检索的servlet,并将该对象保存为文件.我知道我必须使用HttpURLConnection向servlet发出POST请求,但我不知道下面的代码是否正确.
private static HttpURLConnection urlCon;
private static ObjectOutputStream out;
public static void main(String[] args) {
Names names = new Names();
names.setName("ABC");
names.setPlace("Bangalore");
URL url;
try {
url = new URL("http://localhost:6080/HttpClientSerializable/HttpPostServlet");
try {
out = (ObjectOutputStream) urlCon.getOutputStream();
out.writeObject(names);
urlCon = (HttpURLConnection) url.openConnection();
urlCon.setRequestMethod("POST");
urlCon.setDoOutput(true);
out.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
在servlet中,我有以下代码:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ObjectInputStream in = new ObjectInputStream(request.getInputStream());
try {
names = (Names) …Run Code Online (Sandbox Code Playgroud) 我想在我的RCP应用程序中覆盖全局异常处理.每当发生未被捕获的异常时,我想记录它(使用java日志记录),然后退出应用程序.我已经eventLoopException(Throwable exception)在ApplicationWorkbenchAdvisor课堂上覆盖了这个方法.但这只捕获事件循环异常.截至目前,我还覆盖了postStartup()这样的方法:
public void postStartup()
{
Policy.setStatusHandler(new StatusHandler()
{
@Override
public void show(IStatus status, String title)
{
LOGGER.log(Level.SEVERE, "Uncaught Exception", status.getException());
UnexpectedErrorDialog();
PlatformUI.getWorkbench().close();
}
});
}
Run Code Online (Sandbox Code Playgroud)
它将异常记录在我的日志文件中并退出应用程序.但它显然不对,并且在控制台中显示两次异常,因为我所做的只是拦截a中的异常显示gui dialog给用户.那么如何才能正确覆盖/更改全局异常处理,以便使用我的代码(log)而不是默认代码?
我Gson library用来将对象转换为对象,Json反之亦然。我已jars将该库的复制到一个新文件夹中lib,并将其添加到我的项目中的构建路径中Eclipse IDE。
我有一个主类,在其中我将对象转换为Json,toJson()如下所示,并将其发送给servletusing Apache HttpClient's HttpPost()。
Gson gson= new Gson();
String json = gson.toJson(names);
Run Code Online (Sandbox Code Playgroud)
但是在执行以下代码时,我servlet无法将转换Json为Objectusing fromJson()。
Gson gson = new Gson();
Names names = gson.fromJson(s, Names.class);
Run Code Online (Sandbox Code Playgroud)
它引发以下异常:
java.lang.NoClassDefFoundError: com/google/gson/Gson
Run Code Online (Sandbox Code Playgroud)
知道为什么会这样吗?我应该将拷贝jars到WebContent/WEB-INF/lib文件夹中而不是将新文件夹复制到lib吗?
eclipse classpath gson apache-httpcomponents apache-httpclient-4.x
我在ap:dialog中有ap:selectOneMenu.每当我滚动页面时,下拉列表都会从p:selectOneMenu标签中分离,并根据鼠标滚动进行移动.有没有办法将它附加到标签上,以便它不会移动?
以下是具有相同问题的人发布的问题的屏幕截图.SelectOneMenu面板使用鼠标滚轮滚动
我想在我的JSF页面中包含jQuery UI http://code.jquery.com/ui/1.9.0/jquery-ui.js的URL .我看到了许多<h:outputScript>应该使用的问题,但在所有答案中我都没有看到如何包含URL的示例.只有当js文件出现在项目的某个文件夹中时,答案才有意义.
有人可以帮助我在我的页面中包含它吗?
我试图解析一个看起来像这样的Json数组:
{
"FoodItemData": [
{
"country": "GB",
"id": "100",
"name": "Steak and Kidney Pie",
"description": "Tender cubes of steak, with tender lamb kidney is succulent rich gravy. Served with a side of mashed potatoes and peas.",
"category": "Dinner",
"price": "15.95"
},
{
"country": "GB",
"id": "101",
"name": "Toad in the Hole",
"description": "Plump British Pork sausages backed in a light batter. Served with mixed vegetables and a brown onion gravy.",
"category": "Dinner",
"price": "13.95"
},
{
"country": "GB",
"id": "102", …Run Code Online (Sandbox Code Playgroud) 我有一个TableViewer在view我的RCP应用程序.在TableViewer具有List的objects作为输入.是否可以selection使用我设置为输入的List中的对象的索引为特定对象创建TableViewer?例如,我想在每次打开应用程序时为第三个对象设置默认选择.如何设置选择?
我p:selectOneMenu的第一个元素是字符串'请选择',其他项目是要选择的列表.我可以在选择"请选择"时禁用提交按钮,如果选择了其他元素,是否启用按钮?我知道itemDisabled可以使用,但这不是我的要求.
<p:selectOneMenu value="#{bean.value}" id="selectId"
filter="true" required="true" converter="itemConverter"
filterMatchMode="contains" height="120">
<f:selectItem itemLabel="Please select"/>
<f:selectItems value="#{listBean.selectItemList}"></f:selectItems>
</p:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
基本上,我希望在选择第一个项目时禁用提交按钮.
有人可以帮忙吗?
我有一个名为的字段numberOfGuests,它采用整数值。当我提交页面时,我想p:inputText在下一页中numberOfGuests动态插入与值一样多的字段。ui:repeat允许我只迭代一个集合。我想知道我怎么能做到这一点。
谢谢。
我有一个页面,我必须使用键值对关联两个字段并保存.例如,我有很多participant人有prices.如果我使用两个p:inputText字段来输入它们的值,那么支持bean应该如何?
另外,我想p:inputText根据我输入的参与者数量显示这些字段对的数量.我在这里回答了类似的问题如何动态插入一个primefaces输入文本?.但我希望能够将值提交给键值对.
我想有一个rcp应用程序,它不会workspace在启动时创建任何文件夹.我的rcp应用程序不需要持久保存任何插件或用户数据.对于最终用户,工作空间创建似乎是一个令人困惑和烦人的副作用.我怎么能避免这个?
在我看来,每个rcp应用程序都需要插件org.eclipse.core.resources,而类ResourcesPlugin在启动时创建工作区.
我知道-data <workspace_dir>用于指定不同工作空间位置的选项,但我想完全避免创建工作空间.
谢谢你的建议!
我的问题几乎说明了一切.我想在selectOneMenu中有一个占位符文本,但我认为没有任何属性可以指定它.那么如何拥有占位符呢?
我尝试使用<p:watermark>如下所示,但它没有用.
<p:selectOneMenu id="fooMenu">
<f:selectItem itemLabel="foo" itemValue="foo"/>
<f:selectItem itemLabel="goo" itemValue="goo"/>
</p:selectOneMenu>
<p:watermark value="Select" for="fooMenu"></p:watermark>
Run Code Online (Sandbox Code Playgroud) primefaces ×6
java ×5
jsf ×5
eclipse-rcp ×3
eclipse ×2
gson ×2
aggregation ×1
classpath ×1
composition ×1
jquery-ui ×1
jsf-2 ×1
json ×1
logging ×1
rcp ×1
relationship ×1
servlets ×1
startup ×1
workspace ×1