gpt4 book ai didi

java - JSP 找不到 servlet 引用 (404)

转载 作者:搜寻专家 更新时间:2023-10-31 20:19:22 28 4
gpt4 key购买 nike

因此,当我尝试运行此代码示例时 https://www.youtube.com/watch?v=uNRSNDm08wk 我做了我的 servlet 类,而且表格也指向它。但是,当我点击提交时,它似乎没有将 regServlet 识别为我的 servlet 的标识符,因为它给我错误 404。它在 jsp 页面目录中查找文件。有什么地方可以查看这些引用资料吗?

package bean;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class RegServlet
*/
@WebServlet("/RegServlet")
public class RegServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

StringBuilder csvSkills = new StringBuilder();

/**
* @see HttpServlet#HttpServlet()
*/
public RegServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String hdnParam = request.getParameter("pagename");
if(hdnParam.equals("register")){
....

html 形式:

<form action="RegServlet" method="post">
<input type="hidden" name="pagename" value="login"/>
<p>Nombre de Usuario</p>
<input type="text" name="regUserName" required value="usuario" onBlur="if(this.value=='')this.value='usuario'" onFocus="if(this.value=='usuario')this.value='' "><br>
<p>Contraseña</p>
<input type="password" name="regUserPass" required value="Contraseña" onBlur="if(this.value=='')this.value='Contraseña'" onFocus="if(this.value=='Contraseña')this.value='' ">
<br><input type="submit" value="Crear Cuenta">

</form>

最佳答案

我建议您在 JSP 的操作路径中动态添加上下文,如下所示:

<form action="${pageContext.request.contextPath}/sampleServlet">

关于java - JSP 找不到 servlet 引用 (404),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29271423/

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