это java-код: я не получаю никаких сообщений об ошибках, но вывод кода не отображается на веб-сервере. Он показывает веб-адрес как: (http://localhost:6027/HttpSearchBar/Example). Скажите, является ли локальныйхост 6027 является действительным адресом?
package search.com;
import java.io.IO Exception;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Example extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 102831973239L;
public void dopost (HttpServletRequest hreq, HttpServletResponse hres)throws ServletException, IOException{
System.out.println("hello");
try {
hres.setContentType("text/html");
String s1 = hreq.getParameter("username");
String s2 = hreq.getParameter("password");
ServletContext sc = getServletContext();
if ((s1.equals("abc"))&&(s2.equals("xyz"))) {
hres.sendRedirect("welcome");
}else {
PrintWriter pw = hres.getWriter();
pw.print("invalid username/password");
RequestDispatcher rd = sc.getRequestDispatcher("login.html");
rd.include(hreq, hres);
}
} catch (Exception e) {
// TODO: handle exception
System.err.print(e);
}
} }
это html-код:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Example Html</title>
</head>
<body bgcolor=yellow text=blue>
<center>
<h1>
<u>LoginForm</u>
</h1>
<form action="Example" method="post">
UserName<input type="text" name="username">
Password<input type="text" name="Password">
<input type="submit" value="login" /><input type="reset">
</form>
</center>
</body>
</html>
это код web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>HttpSearchBar</display-name>
<servlet>
<servlet-name>Example</servlet-name>
<servlet-class>Example</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Example</servlet-name>
<url-pattern>/Example</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/Example</location>
</error-page>
<error-page>
<error-code>403</error-code>
<location>/Example</location>
</error-page>
<error-page>
<exception-type>javax.servlet.ServletException</exception-type>
<location>/Example</location>
</error-page>
<error-page>
<exception-type>java.io.IOException</exception-type>
<location>/Example</location>
</error-page>
<error-page>
<exception-type>java.lang. Throw able </exception-type>
<location>/search.com.Example</location>
</error-page>
<welcome-file-list>
<welcome-file>login.html</welcome-file>
<welcome-file>login.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>
</web-app>
это отображается, когдасервер запущен:
Oct 22, 2018 6:41:52 PM org.apache.catalina.core.ApplicationDispatcher
invoke
WARNING: Servlet Example is currently unavailable