我的索引看起来像这样:
<HTML>
<head>
<title> JSP Servlet Example</title>
</head>
<body>
<div align="center" style="margin-top: 50px;">
<form action="ServletManager">
Please enter your Username: <input type="text" name="username" size="20px"> <br>
Please enter your Password: <input type="text" name="password" size="20px"> <br><br>
<input type="submit" value="submit">
</form>
</div>
</body>
</HTML>
我的servlet:
package helloweb;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;
public class ServletManager extends HttpServlet {protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// reading the user input
String username = request.getParameter("username");
String password = request.getParameter("password");
PrintWriter out = response.getWriter();
out.println (
"<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" +" +
"http://www.w3.org/TR/html4/loose.dtd\">\n" +
"<html> \n" +
"<head> \n" +
"<meta http-equiv=\"Content-Type\" content=\"text/html; " +
"charset=ISO-8859-1\"> \n" +
"<title> JSP Servlet Example </title> \n" +
"</head> \n" +
"<body> <div align='center'> \n" +
"<style= \"font-size=\"12px\" color='black'\"" + "\">" +
"Username: " + username + " <br> " +
"Password: " + password +
"</font></body> \n" +
"</html>"
);
}
}
我的XML:http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd“版本=“ 3.0”>JSPServlet示例
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>helloweb.ServletManager</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/ServletManager.java</url-pattern>
</servlet-mapping>
这是我的问题:
Firefox无法在/ C:/ Users / HP / IdeaProjects / ourdemo / web / ServletManager?username = hello&password = hello找到该文件。
我在tomcat 7服务器上托管。
出现第一页。我输入用户名和密码,我得到了。请帮助。
请在web.xml中对此进行更改,然后检查/ ServletManagerhttps://javabelazy.blogspot.com/2010/02/student-registration-form-in-java.html(工作代码)