forms - JSP 表单 "action"可以采用什么值?

标签 forms jsp action

JSP 表单 Action 可以是什么? 我有一个 Login.jsp 页面供用户结束详细信息。 我可以在表单操作中提供 servlet 类吗?

这是 servlet 代码。

package mybean;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public LoginServlet() {
    super();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try
    {
        System.out.println("In the Login Servlet");
        LoginBean user = new LoginBean();
        user.setUemail(request.getParameter("uemail"));
        user.setUpass(request.getParameter("upass"));
        user = LoginDAO.login(user);
        if(user.isValid())
        {
            HttpSession session = request.getSession(true);
            session.setAttribute("currentSessionUser",user);
            response.sendRedirect("LoginSuccess.jsp");
        }else
            response.sendRedirect("LoginFailed.jsp");
    } catch (Throwable exc)
    {
        System.out.println(exc);
    }
}

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}

}

最佳答案

根据 specs , 它可以采用任何有效的 URI

This attribute specifies a form processing agent. User agent behavior for a value other than an HTTP URI is undefined.

我可以在表单操作中提供 servlet 类吗?

是的,如果 servlet 类名解析为 web.xml 中映射的有效 URL,否则您将遇到 404

让我们考虑您的 JSP 是应用程序的根

<FORM action="someServletName" method="post">

现在这将被解析为 protocol://servername:port/context/someServletName 。现在你应该在某个地方有 /someServletName 的映射,要么在 web.xml 或通过 注释 到 Servlet 或 JSP。

<servlet>
     <servlet-name>someServletName</servlet-name>
     <servlet-path>packageName.servletName</servlet-path>
</servlet>
<servlet-mapping>
     <servlet-name>someServletName</servlet-name>
     <url-pattern>/someServletName</url-pattern>
</servlet-mapping>

关于forms - JSP 表单 "action"可以采用什么值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17474346/

相关文章:

java - 支柱2 : textbox label is not displayed

forms - 带有 INPUT 行高的 Firefox 错误?有什么解决方法吗?

ruby-on-rails - Ruby on Rails : New controller for photos?

javascript - jqgrid从rest服务中检索JSON数据但不显示它

java - 优化应用程序服务器静态内容的吞吐量

action - Ansible - 打印消息 - 调试 : msg ="line1\n {{ var2 }}\n line3 with var3 = {{ var3 }}"

android - 测试intent是否可用

html - 将表单中心的标签放置在 twitter bootstrap 中

javascript - 我收到 WARN : IntentDialog - no intent handler found for null when I fill out a form Node. js Bot 框架

eclipse - Eclipse 动态 Web 项目中静态文件目录的放置位置