当我尝试通过 localhost/testVaadin/ 在浏览器中加载 servlet 时出现 vaadin 和 servlet 错误
我想执行这个示例来看看 vaadin 是如何工作的,因为我必须使用活动资源管理器来实现一个 BPMN,它使用 vaadin 作为 UI 框架。
我附上了代码和 web.xml 加上抛出的异常。
package com.example.testvaadin;
import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.util.IndexedContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Form;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
我的课
public class SimpleAddressBook extends Application {
变量
private static String[] fields = { "First Name", "Last Name", "Company",
"Mobile Phone", "Work Phone", "Home Phone", "Work Email",
"Home Email", "Street", "Zip", "City", "State", "Country" };
private static String[] visibleCols = new String[] { "Last Name",
"First Name", "Company" };
private Table contactList = new Table();
private Form contactEditor = new Form();
private HorizontalLayout bottomLeftCorner = new HorizontalLayout();
private Button contactRemovalButton;
private IndexedContainer addressBookData = createDummyData();
职能
@Override
public void init() {
initLayout();
initContactAddRemoveButtons();
initAddressList();
initFilteringControls();
}
private void initLayout() {
HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();
setMainWindow(new Window("Address Book", splitPanel));
VerticalLayout left = new VerticalLayout();
left.setSizeFull();
left.addComponent(contactList);
contactList.setSizeFull();
left.setExpandRatio(contactList, 1);
splitPanel.addComponent(left);
splitPanel.addComponent(contactEditor);
contactEditor.setCaption("Contact details editor");
contactEditor.setSizeFull();
contactEditor.getLayout().setMargin(true);
contactEditor.setImmediate(true);
bottomLeftCorner.setWidth("100%");
left.addComponent(bottomLeftCorner);
}
private void initContactAddRemoveButtons() {
// New item button
bottomLeftCorner.addComponent(new Button("+",
new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// Add new contact "John Doe" as the first item
Object id = ((IndexedContainer) contactList
.getContainerDataSource()).addItemAt(0);
contactList.getItem(id).getItemProperty("First Name")
.setValue("John");
contactList.getItem(id).getItemProperty("Last Name")
.setValue("Doe");
// Select the newly added item and scroll to the item
contactList.setValue(id);
contactList.setCurrentPageFirstItemId(id);
}
}));
// Remove item button
contactRemovalButton = new Button("-", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
contactList.removeItem(contactList.getValue());
contactList.select(null);
}
});
contactRemovalButton.setVisible(false);
bottomLeftCorner.addComponent(contactRemovalButton);
}
private void initAddressList() {
contactList.setContainerDataSource(addressBookData);
contactList.setVisibleColumns(visibleCols);
contactList.setSelectable(true);
contactList.setImmediate(true);
contactList.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
Object id = contactList.getValue();
contactEditor.setItemDataSource(id == null ? null : contactList
.getItem(id));
contactRemovalButton.setVisible(id != null);
}
});
}
private void initFilteringControls() {
for (final String pn : visibleCols) {
final TextField sf = new TextField();
bottomLeftCorner.addComponent(sf);
sf.setWidth("100%");
sf.setInputPrompt(pn);
sf.setImmediate(true);
bottomLeftCorner.setExpandRatio(sf, 1);
sf.addListener(new Property.ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
addressBookData.removeContainerFilters(pn);
if (sf.toString().length() > 0 && !pn.equals(sf.toString())) {
addressBookData.addContainerFilter(pn, sf.toString(),
true, false);
}
getMainWindow().showNotification(
"" + addressBookData.size() + " matches found");
}
});
}
}
private static IndexedContainer createDummyData() {
String[] fnames = { "Peter", "Alice", "Joshua", "Mike", "Olivia",
"Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene",
"Lisa", "Marge" };
String[] lnames = { "Smith", "Gordon", "Simpson", "Brown", "Clavel",
"Simons", "Verne", "Scott", "Allison", "Gates", "Rowling",
"Barks", "Ross", "Schneider", "Tate" };
IndexedContainer ic = new IndexedContainer();
for (String p : fields) {
ic.addContainerProperty(p, String.class, "");
}
// Create dummy data by randomly combining first and last names
for (int i = 0; i < 1000; i++) {
Object id = ic.addItem();
ic.getContainerProperty(id, "First Name").setValue(
fnames[(int) (fnames.length * Math.random())]);
ic.getContainerProperty(id, "Last Name").setValue(
lnames[(int) (lnames.length * Math.random())]);
}
return ic;
}
}
这是java部分
而 web.xml 是
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>testVaadin</display-name>
<context-param>
<description>
Vaadin production mode</description>
<param-name>productionMode</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>Testvaadin Application</servlet-name>
<servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
<init-param>
<description>
Vaadin application class to start</description>
<param-name>application</param-name>
<param-value>com.example.testvaadin.SimpleAddressBook</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Testvaadin Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
我使用 tomcat 作为网络服务器(6.0.32)
所以错误是:
rg.apache.catalina.core.StandardWrapperValve 调用 GRAVE:Exception lors de l'allocation pour la servlet Testvaadin Application javax.servlet.ServletException:无法加载应用程序类:com.vaadin.terminal.gwt 上的 com.example.testvaadin.SimpleAddressBook .server.ApplicationServlet.init(ApplicationServlet.java:71) 在 org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173) 在 org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809 ) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 在 org.apache.catalina.core.StandardHostValve 的 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)。在 org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) 在 org.apache.catalina.core 调用(StandardHostValve.java:127)。StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859) at org .apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) at java.lang.Thread.run (线程.java:662)