我尝试在Lubuntu 13.10上的eclipse kepler上创建简单的web项目。
我在这里遇到了一些麻烦。
当我运行这个项目时:
Run as
=> Run on server
它没有打开注册表。
看起来如下:
用于加载用户表单我需要在网址/addUser
的末尾添加。
它应该加载AddUserServlet
并将请求转发给adduser.jsp
。
这是我的weeb.xml
:
<servlet>
<servlet-name>ShowUserServlet</servlet-name>
<servlet-class>com.lab.controler.servlets.ShowUsersServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ShowUserServlet</servlet-name>
<url-pattern>/showUsers</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>RegistrationServlet</servlet-name>
<servlet-class>com.lab.controler.servlets.AddUserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegistrationServlet</servlet-name>
<url-pattern>/addUser</url-pattern>
</servlet-mapping>
AddUserServlet
的内容:
公共类AddUserServlet扩展了HttpServlet {
UserService userService = new UserService();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("/pages/addUser.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
User user = new User();
takeParameterFromRequest(request, user);
boolean result = userService.addUser(user);
getServletContext().setAttribute("boolean", result);
request.getRequestDispatcher("/pages/UserAddingResult.jsp").forward(request, response);
}
private void takeParameterFromRequest(HttpServletRequest request, User user) {
user.setName(request.getParameter("firstname"));
user.setLastname(request.getParameter("lastname"));
user.setEmail(request.getParameter("email"));
user.setGender(request.getParameter("optionsRadios"));
user.setCity(request.getParameter("city"));
}
addUser.jsp
的摘要:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration Form</title>
</head>
<body>
<h1 align="center">
<b>Registration form</b>
</h1>
<form method="post" action="addUser">
<div class="control-group">
<label class="control-label">First Name</label>
<div class="controls">
<input type="text" name="firstname" maxlength="20"
placeholder="first name" />
</div>
</div>
<div class="control-group">
<label class="control-label">Last Name</label>
<div class="controls">
<input type="text" name="lastname" maxlength="20"
placeholder="last name" />
</div>
</div>
这是项目层次结构:
并加载表单:
我无法弄清楚为什么会发生这种情况......任何建议都值得赞赏。
更新
我按照保罗建议,并添加到 web.xml :
<welcome-file-list>
<welcome-file>addUser</welcome-file>
</welcome-file-list>
这个已加载的注册表单,但在填写输入并按下提交后会显示下一个:
以下是来自打印堆栈跟踪的片段:
INFO: Server startup in 964 ms
Feb 05, 2014 1:47:16 PM org.apache.jasper.compiler.TldLocationsCache tldScanJar
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Feb 05, 2014 1:47:16 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.ClassNotFoundException: javax.servlet.jsp.tagext.TagLibraryValidator
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
答案 0 :(得分:1)
我不太确定这是你的问题,但你试过吗
http://localhost:8080/UserRegistrationProject/addUser
这应该打开注册页面
如果您希望在运行的服务器上自动打开此表单,请在web.xml中添加“addUser”值
<welcome-file-list>
<welcome-file>addUser</welcome-file>
</welcome-file-list>