The requested resource (/Login/LoginServlet) is not available.
不知道Therequestedresource(/Login/LoginServlet)isnotavailable.这是怎么回事!我是用MyEclipse来编的一个简单...
不知道The requested resource (/Login/LoginServlet) is not available.
这是怎么回事!我是用MyEclipse来编的一个简单的登录的小程序,
package com.tLogin.model;
public class javaBean {
private String UserName;
private String UserPass;
public String getUsername()
{
return UserName;
}
public void setUsername (String username)
{
this.UserName = username;
}
public String getUserpass()
{
return UserPass;
}
public void setUserpass(String userpass)
{
this.UserPass = userpass;
}
public boolean validate(String username,String userpass)
{
if(username.equals("zhangsan") && userpass.equals("123456"))
return true;
else
return false;
}
}
//=========================
package com.tLogin.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import com.tLogin.model.javaBean;
import javax.servlet.RequestDispatcher;
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 {
public loginServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userid = request.getParameter("userid");
String userpass = request.getParameter("userpass");
javaBean user = new javaBean();
boolean b = user.validate(userid, userpass);
String forward;
if(b)
{
HttpSession session = request.getSession(true);
session.setAttribute("userid",userid);
forward = "success.jsp";
}
else
{
forward = "failure.jsp";
}
RequestDispatcher dispatcher = request.getRequestDispatcher(forward);
dispatcher.forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
public void init() throws ServletException {
}
}
//================
<body>
<form method = " post " action = "/com/servlet/loginServlet" >
用户名: <input type = "text" name = “username”> <br>
密 码: <input type = "text" name = “password”> <br>
<input type = "submit" value = "提交">
</form> 展开
这是怎么回事!我是用MyEclipse来编的一个简单的登录的小程序,
package com.tLogin.model;
public class javaBean {
private String UserName;
private String UserPass;
public String getUsername()
{
return UserName;
}
public void setUsername (String username)
{
this.UserName = username;
}
public String getUserpass()
{
return UserPass;
}
public void setUserpass(String userpass)
{
this.UserPass = userpass;
}
public boolean validate(String username,String userpass)
{
if(username.equals("zhangsan") && userpass.equals("123456"))
return true;
else
return false;
}
}
//=========================
package com.tLogin.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import com.tLogin.model.javaBean;
import javax.servlet.RequestDispatcher;
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 {
public loginServlet() {
super();
}
public void destroy() {
super.destroy();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userid = request.getParameter("userid");
String userpass = request.getParameter("userpass");
javaBean user = new javaBean();
boolean b = user.validate(userid, userpass);
String forward;
if(b)
{
HttpSession session = request.getSession(true);
session.setAttribute("userid",userid);
forward = "success.jsp";
}
else
{
forward = "failure.jsp";
}
RequestDispatcher dispatcher = request.getRequestDispatcher(forward);
dispatcher.forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
public void init() throws ServletException {
}
}
//================
<body>
<form method = " post " action = "/com/servlet/loginServlet" >
用户名: <input type = "text" name = “username”> <br>
密 码: <input type = "text" name = “password”> <br>
<input type = "submit" value = "提交">
</form> 展开
1个回答
展开全部
路径问题,如果你的web.xml中的 loginServlet.java的url-pattern是
<url-pattern>/com/servlet/loginServlet</url-pattern>
那么你的action中应该这么写:action = "com/servlet/loginServlet"
你servlet的url不要写复杂了,不然很容易在路径上出错的
<url-pattern>/com/servlet/loginServlet</url-pattern>
那么你的action中应该这么写:action = "com/servlet/loginServlet"
你servlet的url不要写复杂了,不然很容易在路径上出错的
更多追问追答
追问
这种方法我尝试过的了,MyEclipse自动生成的路径是servlet/loginServlet,但是我用loginServlet或者servlet/loginServlet都不行,最后我就把xml文档里面的路径修改成/com/servlet/loginServlet,但是还是不行!
追答
路径不对,是报404错误
一点要注意,在action的url比里的少了前边的“/”
如果你的jsp文件并不和最初生成的index.jsp在同一个文件夹下的话,比如你新建了一个文件夹存放jsp文件,此时action="../loginServlet"。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询