我是JSP的新手,我们在Uni中给出了一些代码示例。教程,但它不起作用。
这是我的Server.java
public class Server{
public static void main(String[] args) {
Server server = new Server(8080);
// As we are using the Servlet to server responses remove the resource handler.
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[]{"index.jsp", "index.html"});
resource_handler.setResourceBase("./target/classes/webapp");
// Initialise Servlet context handler
ServletContextHandler context = new ServletContextHandler(
ServletContextHandler.SESSIONS);
context.setContextPath("/");
// Add Servlets with holders to context handler
ServletHolder indexHolder = new ServletHolder(new IndexServlet());
context.addServlet(indexHolder, "/index.jsp");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] {context, resource_handler, new DefaultHandler() });
server.setHandler(handlers);
try {
server.start();
} catch (Exception ex) {
ex.printStackTrace();
System.exit(-1);
}
}
}
这是我的索引Servlet
public class IndexServlet extends HttpServlet {
private static final long serialVersionUID = 0x1C30CCL;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Set response content type.
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
}
}
这是我的index.jsp
<!doctype html>
<html>
<head>
<title>Book a hotel!</title>
</head>
<body>
<form action="index.jsp" method="post">
<input type="text" name="username" placeholder="Enter Username" />
<input type="Submit">
</form>
<p> The current server time is: <%= new java.util.Date() %> </p>
</body>
</html>
当我访问localhost:8080 / index.jsp&lt; %%&gt;中的数据时没有被解析!帮助