问题描述
JSP表单动作可以是什么?我有一个Login.jsp页面供用户结束详细信息.我可以在表单操作中给servlet类吗?
What can a JSP form action be?I have a Login.jsp page for the user to end the details.Can i give the servlet class in the form action?
这是servlet代码.
here is the the servlet code.
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 {
}
}
推荐答案
As per the specs , it can take any valid URI
我可以采取动作的形式提供servlet类吗?
是的,如果Servlet类名称解析为web.xml
中映射的有效URL,否则您将遇到 404 .
Yes if the servlet class name resolves to a valid URL mapped in the web.xml
or else you will encounter a 404 .
让我们考虑您的JSP位于应用程序的根目录,然后
Let us consider your JSP is at the root of the application, then
<FORM action="someServletName" method="post">
现在这将解析为protocol://servername:port/context/someServletName
.现在应该在 web.xml 中或通过 annotation 将/someServletName
映射到Servlet.或JSP.
Now this will be resolved as protocol://servername:port/context/someServletName
.Now somewhere you should have a mapping for /someServletName
, either in web.xml or through annotation to a Servlet or 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>
这篇关于JSP可以采用什么值来形成“动作"?拿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!