gpt4 book ai didi

javax/servlet/jsp/tagext/TagLibraryValidator - 运行 Web 项目

转载 作者:行者123 更新时间:2023-12-01 13:31:02 26 4
gpt4 key购买 nike

我尝试在 Lubuntu 13.10 上的 eclipse kepler 上创建简单的 Web 项目。

我在这里遇到了一些麻烦。

当我运行这个项目时:

运行方式 => 在服务器上运行

它不会打开注册表单。

它看起来如下:

registration

为了加载用户表单,我需要在 url 末尾添加 /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的内容:

公共(public)类 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>

这是项目层次结构:

hierarchy

并加载表单查找:

registration form

我不明白为什么会发生这种情况...任何建议都很感激。

更新:

我遵循了Paul的建议,并添加到了web.xml:

    <welcome-file-list>
<welcome-file>addUser</welcome-file>
</welcome-file-list>

此加载注册表单,但在填写输入并按提交后,它显示下一个:

500 http status

这是打印堆栈跟踪的片段:

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)

最佳答案

我不太确定这是你的问题,但你尝试过吗

http://localhost:8080/UserRegistrationProject/addUser

这应该打开注册页面

如果您希望此表单在服务器运行时自动打开,请在 web.xml 中添加“addUser”值

<welcome-file-list>
<welcome-file>addUser</welcome-file>
</welcome-file-list>

关于javax/servlet/jsp/tagext/TagLibraryValidator - 运行 Web 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21575029/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com