请问j2ee的目录架构是怎么样的?如何运行?

asdfavewvwe 2013-08-20 02:52:43
我的目录架构这样子对吗?


我想要运行form.html,再通过html的提交到HelloServlet.java这个servlet中,如何运行?

我的form.html:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Insert title here</title>
</head>
<body>
<form action="hello.avi" method="post">
名称:<input type="text" name="user" /><br />
密码:<input type="password" name="passwd" /><br /><br />
<input type="submit" name="login" value="送出" />
</form>
</body>
</html>


HelloServlet.java:

package cc.openhome;

import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
* Servlet implementation class HelloServlet
*/
@WebServlet(
name="Hello",
urlPatterns={"/hello.avi"},
loadOnStartup=1
)
public class HelloServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public HelloServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String body = readBody(request);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet BodyView</title>");
out.println("</head>");
out.println("<body>" + body + "</body>");
out.println("</html>");
}

private String readBody(HttpServletRequest request) throws IOException {
BufferedReader reader = request.getReader();
String input = null;
String requestBody = "";
while ((input = reader.readLine()) != null) {
requestBody += input + "<br />";
}
return requestBody;
}

}

...全文
165 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
asdfavewvwe 2013-08-20
  • 打赏
  • 举报
回复
引用 4 楼 u011540494 的回复:
[quote=引用 2 楼 u011540494 的回复:] 在eclipse里面添加一个tomcat服务器,然后把项目添加到tomcat服务器上,再启动服务器,用浏览器就可也访问了。
form.html放在WEB-INF是不能通过浏览器直接访问的。必须通过servlet访问它。如果要直接访问,必须把它放在WEB-INF外面也就是WebContent下。[/quote] 我明白了。。谢谢。。
wind_elf 2013-08-20
  • 打赏
  • 举报
回复
引用 2 楼 u011540494 的回复:
在eclipse里面添加一个tomcat服务器,然后把项目添加到tomcat服务器上,再启动服务器,用浏览器就可也访问了。
form.html放在WEB-INF是不能通过浏览器直接访问的。必须通过servlet访问它。如果要直接访问,必须把它放在WEB-INF外面也就是WebContent下。
asdfavewvwe 2013-08-20
  • 打赏
  • 举报
回复
引用 2 楼 u011540494 的回复:
在eclipse里面添加一个tomcat服务器,然后把项目添加到tomcat服务器上,再启动服务器,用浏览器就可也访问了。


是啊。。。我也是这样子啊。。。但这个目录结构对不对啊,特别是servlet放的位置(在放在WEB-INF里还是怎么样的);



我运行的结果:(我先运行html文件,这个没错吧)


wind_elf 2013-08-20
  • 打赏
  • 举报
回复
在eclipse里面添加一个tomcat服务器,然后把项目添加到tomcat服务器上,再启动服务器,用浏览器就可也访问了。
asdfavewvwe 2013-08-20
  • 打赏
  • 举报
回复
加上为什么POST提交会提交到缓存里?

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧