Skip to content

Commit 59712c0

Browse files
committed
j2ee examples
1 parent 86ad871 commit 59712c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1059
-0
lines changed

spring-mvc/web-snippet/.classpath

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
31+
<attributes>
32+
<attribute name="maven.pomderived" value="true"/>
33+
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
34+
</attributes>
35+
</classpathentry>
36+
<classpathentry kind="output" path="target/classes"/>
37+
</classpath>

spring-mvc/web-snippet/.project

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>web-snippet</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.eclipse.wst.validation.validationbuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
<buildCommand>
29+
<name>org.eclipse.m2e.core.maven2Builder</name>
30+
<arguments>
31+
</arguments>
32+
</buildCommand>
33+
</buildSpec>
34+
<natures>
35+
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
36+
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
37+
<nature>org.eclipse.jdt.core.javanature</nature>
38+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
39+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
40+
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
41+
</natures>
42+
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="src/main/webapp"/>
4+
<classpathentry kind="src" path="target/m2e-wtp/web-resources"/>
5+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
6+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
7+
<attributes>
8+
<attribute name="hide" value="true"/>
9+
</attributes>
10+
</classpathentry>
11+
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
12+
<classpathentry kind="output" path=""/>
13+
</classpath>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
4+
org.eclipse.jdt.core.compiler.compliance=1.7
5+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8+
org.eclipse.jdt.core.compiler.source=1.7
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
2+
<wb-module deploy-name="web-snippet">
3+
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
4+
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
5+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
6+
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
7+
<property name="context-root" value="web-snippet"/>
8+
<property name="java-output-path" value="/web-snippet/target/classes"/>
9+
</wb-module>
10+
</project-modules>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<root>
2+
<facet id="jst.jaxrs">
3+
<node name="libprov">
4+
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/>
5+
</node>
6+
</facet>
7+
</root>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<faceted-project>
3+
<fixed facet="wst.jsdt.web"/>
4+
<installed facet="jst.web" version="3.1"/>
5+
<installed facet="wst.jsdt.web" version="1.0"/>
6+
<installed facet="java" version="1.7"/>
7+
<installed facet="jst.jaxrs" version="2.0"/>
8+
</faceted-project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Window
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
disabled=06target
2+
eclipse.preferences.version=1

spring-mvc/web-snippet/pom.xml

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.web</groupId>
5+
<artifactId>web-snippet</artifactId>
6+
<packaging>war</packaging>
7+
<version>1.0.0</version>
8+
<name>web-snippet</name>
9+
10+
<properties>
11+
<java-version>1.7</java-version>
12+
<org.springframework-version>4.3.5.RELEASE</org.springframework-version>
13+
<org.springframework.security-version>4.3.5.RELEASE</org.springframework.security-version>
14+
<org.aspectj-version>1.8.1</org.aspectj-version>
15+
<org.slf4j-version>1.7.12</org.slf4j-version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.12</version>
23+
<scope>test</scope>
24+
</dependency>
25+
26+
<!-- Spring -->
27+
<dependency>
28+
<groupId>org.springframework</groupId>
29+
<artifactId>spring-test</artifactId>
30+
<version>${org.springframework-version}</version>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework</groupId>
34+
<artifactId>spring-tx</artifactId>
35+
<version>${org.springframework-version}</version>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.springframework</groupId>
39+
<artifactId>spring-webmvc</artifactId>
40+
<version>${org.springframework-version}</version>
41+
</dependency>
42+
43+
<!-- Servlet -->
44+
<dependency>
45+
<groupId>org.apache.tomcat</groupId>
46+
<artifactId>tomcat-servlet-api</artifactId>
47+
<version>8.5.11</version>
48+
</dependency>
49+
50+
<dependency>
51+
<groupId>javax.servlet</groupId>
52+
<artifactId>javax.servlet-api</artifactId>
53+
<version>3.1.0</version>
54+
</dependency>
55+
56+
57+
58+
<!-- jsp -->
59+
<dependency>
60+
<groupId>javax.servlet.jsp</groupId>
61+
<artifactId>jsp-api</artifactId>
62+
<version>2.2</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>javax.el</groupId>
66+
<artifactId>javax.el-api</artifactId>
67+
<version>3.0.0</version>
68+
</dependency>
69+
<dependency>
70+
<groupId>javax.servlet.jsp.jstl</groupId>
71+
<artifactId>jstl-api</artifactId>
72+
<version>1.2</version>
73+
<exclusions>
74+
<exclusion>
75+
<groupId>javax.servlet</groupId>
76+
<artifactId>servlet-api</artifactId>
77+
</exclusion>
78+
</exclusions>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.glassfish.web</groupId>
82+
<artifactId>jstl-impl</artifactId>
83+
<version>1.2</version>
84+
<exclusions>
85+
<exclusion>
86+
<groupId>javax.servlet</groupId>
87+
<artifactId>servlet-api</artifactId>
88+
</exclusion>
89+
</exclusions>
90+
</dependency>
91+
92+
<!-- JSR 303 with Hibernate Validator -->
93+
<dependency>
94+
<groupId>javax.validation</groupId>
95+
<artifactId>validation-api</artifactId>
96+
<version>1.1.0.Final</version>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.hibernate</groupId>
100+
<artifactId>hibernate-validator</artifactId>
101+
<version>5.3.4.Final</version>
102+
</dependency>
103+
104+
<!-- javax- restful -->
105+
<dependency>
106+
<groupId>javax.ws.rs</groupId>
107+
<artifactId>jsr311-api</artifactId>
108+
<version>1.1.1</version>
109+
</dependency>
110+
<dependency>
111+
<groupId>javax.ws.rs</groupId>
112+
<artifactId>javax.ws.rs-api</artifactId>
113+
<version>2.0.1</version>
114+
</dependency>
115+
116+
<!-- log -->
117+
<dependency>
118+
<groupId>org.apache.logging.log4j</groupId>
119+
<artifactId>log4j-api</artifactId>
120+
<version>2.8</version>
121+
</dependency>
122+
<dependency>
123+
<groupId>org.apache.logging.log4j</groupId>
124+
<artifactId>log4j-core</artifactId>
125+
<version>2.8</version>
126+
</dependency>
127+
<dependency>
128+
<groupId>org.apache.logging.log4j</groupId>
129+
<artifactId>log4j-web</artifactId>
130+
<version>2.7</version>
131+
</dependency>
132+
<dependency>
133+
<groupId>org.slf4j</groupId>
134+
<artifactId>slf4j-api</artifactId>
135+
<version>1.7.21</version>
136+
</dependency>
137+
</dependencies>
138+
139+
<build>
140+
<plugins>
141+
<plugin>
142+
<groupId>org.apache.maven.plugins</groupId>
143+
<artifactId>maven-compiler-plugin</artifactId>
144+
<version>2.3.2</version>
145+
<configuration>
146+
<source>${java-version}</source>
147+
<target>${java-version}</target>
148+
</configuration>
149+
</plugin>
150+
<!-- jetty插件 -->
151+
<plugin>
152+
<groupId>org.eclipse.jetty</groupId>
153+
<artifactId>jetty-maven-plugin</artifactId>
154+
<version>9.0.6.v20130930</version>
155+
<configuration>
156+
<webApp>
157+
<contextPath>/${project.artifactId}</contextPath>
158+
</webApp>
159+
</configuration>
160+
</plugin>
161+
<!-- <plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-project</artifactId>
162+
<version>9.4.3.v20170317</version> <configuration> <webApp> <contextPath>/</contextPath>
163+
</webApp> <httpConnector> <port>18080</port> </httpConnector> <stopKey>shutdown</stopKey>
164+
<stopPort>9966</stopPort> <scanIntervalSeconds>2</scanIntervalSeconds> <reload>manual</reload>
165+
<dumpOnStart>true</dumpOnStart> </configuration> </plugin> -->
166+
</plugins>
167+
</build>
168+
</project>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package com.web.javax;
2+
3+
import javax.ws.rs.GET;
4+
import javax.ws.rs.Path;
5+
import javax.ws.rs.PathParam;
6+
import javax.ws.rs.Produces;
7+
import javax.ws.rs.core.MediaType;
8+
import javax.xml.bind.JAXBElement;
9+
import javax.xml.namespace.QName;
10+
11+
import com.web.javax.domain.User;
12+
13+
@Path("/")
14+
public class RestExample
15+
{
16+
private static final String ROOT_NODE = "root";
17+
18+
// -----------例子1:返回text ----------
19+
@GET //这是Restful中的GET方法
20+
@Path("/text") //路径为/rest/hello/text
21+
@Produces(MediaType.TEXT_PLAIN) //response的ContentType为text/plain
22+
public String getHelloWorld() {
23+
// 因为输出是text/plain,所以返回一个String,经过测试,即使有toString(),也不能是其他类型
24+
return "Hello, my frist RESTFul Test";
25+
}
26+
27+
// -----------例子2:返回Json,JAXBElement<String>格式 ----------
28+
@GET
29+
@Path("/json")
30+
@Produces(MediaType.APPLICATION_JSON)
31+
public JAXBElement<String> getHelloWorldJSON()
32+
{
33+
JAXBElement<String> result = new JAXBElement<String>(new QName("", ROOT_NODE), String.class, "Hello,JSR!");
34+
return result;
35+
}
36+
37+
// -----------例子3:URL带参数,返回Json,直接对象格式 ----------
38+
@GET
39+
@Path("/json/user/{id}")
40+
@Produces(MediaType.APPLICATION_JSON)
41+
public User getMe(@PathParam("id") String id)
42+
{
43+
User user = new User();
44+
user.setId(id);
45+
user.setName(id + "-Test");
46+
user.setEmail(id + "@hello");
47+
return user;
48+
}
49+
50+
// -----------例子4:URL带参数,返回XML格式 ----------
51+
@GET
52+
@Path("/xml/user/{id}")
53+
@Produces(MediaType.APPLICATION_XML)
54+
public User getUserInXML(@PathParam("id") String id)
55+
{
56+
User user = new User();
57+
user.setId(id);
58+
user.setName(id + "-TestXML");
59+
user.setEmail(id + "@XML");
60+
return user;
61+
}
62+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy