Skip to content

Commit 283bd33

Browse files
author
xiachaochao
committed
servlet第二次提交
1 parent 26d7bff commit 283bd33

4 files changed

Lines changed: 165 additions & 47 deletions

File tree

JavaWeb/WebContent/HTML/label.html

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
<title>Insert title here</title>
66
</head>
77
<body>
8-
<!--当用户单击表单控件前面的标签时,该表单控件就可以获得输入焦点 -->
9-
<form action="http://www.crazyjava.cn">
10-
<!--隐式关联 -->
11-
<label for="username"/>单行文本框</label>
12-
<input id="username" name="username" type="text"/><br/>
13-
<!--显示关联 -->
14-
<label>密码框:<input id="password" name="password" type="password"/></label>
15-
</form>
8+
<!--当用户单击表单控件前面的标签时,该表单控件就可以获得输入焦点 -->
9+
<form action="http://www.crazyjava.cn">
10+
<!--隐式关联 -->
11+
<label for="username" />
12+
单行文本框
13+
</label>
14+
<input id="username" name="username" type="text" />
15+
<br />
16+
<!--显示关联 -->
17+
<label>
18+
密码框:
19+
<input id="password" name="password" type="password" />
20+
</label>
21+
</form>
1622
</body>
1723
</html>

JavaWeb/WebContent/WEB-INF/web.xml

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
4-
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
5-
id="WebApp_ID" version="3.1">
6-
<display-name>JavaWeb</display-name>
7-
<welcome-file-list>
8-
<welcome-file>index.html</welcome-file>
9-
<welcome-file>index.htm</welcome-file>
10-
<welcome-file>index.jsp</welcome-file>
11-
<welcome-file>default.html</welcome-file>
12-
<welcome-file>default.htm</welcome-file>
13-
<welcome-file>default.jsp</welcome-file>
14-
</welcome-file-list>
15-
<servlet>
16-
<servlet-name>ServletDemo</servlet-name>
17-
<servlet-class>com.xinan.servlet.ServletDemo01</servlet-class>
18-
</servlet>
19-
<servlet-mapping>
20-
<servlet-name>ServletDemo</servlet-name>
21-
<url-pattern>/ServletDemo</url-pattern>
22-
</servlet-mapping>
23-
<servlet>
24-
<servlet-name>MyLoginServletDemo</servlet-name>
25-
<servlet-class>com.xinan.servlet.MyLoginServletDemo</servlet-class>
26-
</servlet>
27-
<servlet-mapping>
28-
<servlet-name>MyLoginServletDemo</servlet-name>
29-
<url-pattern>/MyLoginServletDemo</url-pattern>
30-
</servlet-mapping>
31-
32-
<servlet>
33-
<servlet-name>life</servlet-name>
34-
<servlet-class>com.xinan.servlet.LifeCycleServlet</servlet-class>
35-
</servlet>
36-
<servlet-mapping>
37-
<servlet-name>life</servlet-name>
38-
<url-pattern>/LifeServlet</url-pattern>
39-
</servlet-mapping>
40-
2+
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
3+
<display-name>JavaWeb</display-name>
4+
<welcome-file-list>
5+
<welcome-file>index.html</welcome-file>
6+
<welcome-file>index.htm</welcome-file>
7+
<welcome-file>index.jsp</welcome-file>
8+
<welcome-file>default.html</welcome-file>
9+
<welcome-file>default.htm</welcome-file>
10+
<welcome-file>default.jsp</welcome-file>
11+
</welcome-file-list>
12+
<servlet>
13+
<servlet-name>ServletDemo</servlet-name>
14+
<servlet-class>com.xinan.servlet.ServletDemo01</servlet-class>
15+
</servlet>
16+
<servlet-mapping>
17+
<servlet-name>ServletDemo</servlet-name>
18+
<url-pattern>/ServletDemo</url-pattern>
19+
</servlet-mapping>
20+
<servlet>
21+
<servlet-name>MyLoginServletDemo</servlet-name>
22+
<servlet-class>com.xinan.servlet.MyLoginServletDemo</servlet-class>
23+
</servlet>
24+
<servlet-mapping>
25+
<servlet-name>MyLoginServletDemo</servlet-name>
26+
<url-pattern>/MyLoginServletDemo</url-pattern>
27+
</servlet-mapping>
28+
<servlet>
29+
<servlet-name>life</servlet-name>
30+
<servlet-class>com.xinan.servlet.LifeCycleServlet</servlet-class>
31+
</servlet>
32+
<servlet-mapping>
33+
<servlet-name>life</servlet-name>
34+
<url-pattern>/LifeServlet</url-pattern>
35+
</servlet-mapping>
4136
</web-app>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.javaWeb.bean;
2+
3+
import java.io.IOException;
4+
import java.io.PrintWriter;
5+
6+
import javax.servlet.ServletException;
7+
import javax.servlet.annotation.WebServlet;
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
/**
13+
* Servlet implementation class OutputInfo
14+
*/
15+
@WebServlet("/OutputInfo")
16+
public class OutputInfo extends HttpServlet {
17+
private static final long serialVersionUID = 1L;
18+
19+
/**
20+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
21+
* response)
22+
*/
23+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
24+
throws ServletException, IOException {
25+
// TODO Auto-generated method stub
26+
// response.getWriter().append("Served at:
27+
// ").append(request.getContextPath());
28+
response.setContentType("text/html,");
29+
PrintWriter out = response.getWriter();
30+
31+
}
32+
33+
/**
34+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
35+
* response)
36+
*/
37+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
38+
throws ServletException, IOException {
39+
// TODO Auto-generated method stub
40+
doGet(request, response);
41+
}
42+
43+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.javaWeb.bean;
2+
3+
import java.io.IOException;
4+
import java.io.PrintWriter;
5+
6+
import javax.servlet.ServletConfig;
7+
import javax.servlet.ServletException;
8+
import javax.servlet.annotation.WebInitParam;
9+
import javax.servlet.annotation.WebServlet;
10+
import javax.servlet.http.HttpServlet;
11+
import javax.servlet.http.HttpServletRequest;
12+
import javax.servlet.http.HttpServletResponse;
13+
14+
/**
15+
* Servlet implementation class ServletInitParaDemo
16+
*/
17+
@WebServlet(urlPatterns = { "/ServletInitParaDemo" }, initParams = { @WebInitParam(name = "institute", value = "新安培训"),
18+
@WebInitParam(name = "major", value = "java技术") })
19+
public class ServletInitParaDemo extends HttpServlet {
20+
private static final long serialVersionUID = 1L;
21+
private String myInstitute = null;
22+
private String myMajor = null;
23+
private int count = 0;
24+
25+
/**
26+
* @see HttpServlet#HttpServlet()
27+
*/
28+
public ServletInitParaDemo() {
29+
super();
30+
// TODO Auto-generated constructor stub
31+
}
32+
33+
public void init(ServletConfig config) throws ServletException {
34+
myInstitute = config.getInitParameter("institute");
35+
if (myInstitute == null) {
36+
myInstitute = "";
37+
}
38+
myMajor = config.getInitParameter("major");
39+
if (myMajor == null) {
40+
myMajor = "";
41+
}
42+
/*String strCount = config.getInitParameter("count");
43+
try {
44+
count = Integer.parseInt(strCount);
45+
} catch (Exception e) {
46+
e.printStackTrace();
47+
}*/
48+
}
49+
50+
/**
51+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
52+
* response)
53+
*/
54+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
55+
throws ServletException, IOException {
56+
// TODO Auto-generated method stub
57+
// response.getWriter().append("Served at:
58+
// ").append(request.getContextPath());
59+
response.setContentType("text/html,charset=utf-8");
60+
PrintWriter out = response.getWriter();
61+
out.print("<h3>"+myMajor+"</h3>");
62+
}
63+
64+
/**
65+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
66+
* response)
67+
*/
68+
protected void doPost(HttpServletRequest request, HttpServletResponse response)
69+
throws ServletException, IOException {
70+
// TODO Auto-generated method stub
71+
doGet(request, response);
72+
}
73+
74+
}

0 commit comments

Comments
 (0)