Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e383f54

Browse files
committed
Cambiado el codigo para usar jsp en lugar de print
1 parent 1724a59 commit e383f54

File tree

6 files changed

+117
-172
lines changed

6 files changed

+117
-172
lines changed

.idea/JavaWebApplicationExample.iml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ejemplos.servlet.curso;
22

3+
import javax.servlet.RequestDispatcher;
34
import javax.servlet.ServletException;
45
import javax.servlet.annotation.WebServlet;
56
import javax.servlet.http.HttpServlet;
@@ -18,95 +19,10 @@ protected void doGet(HttpServletRequest request,
1819
PrintWriter out = response.getWriter();
1920

2021
// send HTML page to client
21-
out.println("<html>");
22-
out.println("<head><title>Ejemplo HTML desde Servlet</title>");
23-
out.println("<style>");
24-
out.println("body {\n" +
25-
" display: flex;\n" +
26-
" justify-content: center;\n" +
27-
" align-items: center;\n" +
28-
" min-height: 100vh;\n" +
29-
" background: #eceffc;\n" +
30-
"}\n" +
31-
"\n" +
32-
".btn {\n" +
33-
" padding: 8px 20px;\n" +
34-
" border-radius: 0;\n" +
35-
" overflow: hidden;\n" +
36-
"\n" +
37-
" &::before {\n" +
38-
" position: absolute;\n" +
39-
" content: \"\";\n" +
40-
" top: 0;\n" +
41-
" left: 0;\n" +
42-
" width: 100%;\n" +
43-
" height: 100%;\n" +
44-
" background: linear-gradient(\n" +
45-
" 120deg,\n" +
46-
" transparent,\n" +
47-
" var(--primary-color),\n" +
48-
" transparent\n" +
49-
" );\n" +
50-
" transform: translateX(-100%);\n" +
51-
" transition: 0.6s;\n" +
52-
" }\n" +
53-
"\n" +
54-
" &:hover {\n" +
55-
" background: transparent;\n" +
56-
" box-shadow: 0 0 20px 10px hsla(204, 70%, 53%, 0.5);\n" +
57-
"\n" +
58-
" &::before {\n" +
59-
" transform: translateX(100%);\n" +
60-
" }\n" +
61-
" }\n" +
62-
"}\n" +
63-
"\n" +
64-
".form-input-material {\n" +
65-
" --input-default-border-color: white;\n" +
66-
" --input-border-bottom-color: white;\n" +
67-
" \n" +
68-
" input {\n" +
69-
" color: white;\n" +
70-
" }\n" +
71-
"}\n" +
72-
"\n" +
73-
".login-form {\n" +
74-
" display: flex;\n" +
75-
" flex-direction: column;\n" +
76-
" align-items: center;\n" +
77-
" padding: 50px 40px;\n" +
78-
" color: white;\n" +
79-
" background: rgba(0, 0, 0, 0.8);\n" +
80-
" border-radius: 10px;\n" +
81-
" box-shadow: 0 0.4px 0.4px rgba(128, 128, 128, 0.109),\n" +
82-
" 0 1px 1px rgba(128, 128, 128, 0.155),\n" +
83-
" 0 2.1px 2.1px rgba(128, 128, 128, 0.195),\n" +
84-
" 0 4.4px 4.4px rgba(128, 128, 128, 0.241),\n" +
85-
" 0 12px 12px rgba(128, 128, 128, 0.35);\n" +
86-
"\n" +
87-
" h1 {\n" +
88-
" margin: 0 0 24px 0;\n" +
89-
" }\n" +
90-
"\n" +
91-
" .form-input-material {\n" +
92-
" margin: 12px 0;\n" +
93-
" }\n" +
94-
"\n" +
95-
" .btn {\n" +
96-
" width: 100%;\n" +
97-
" margin: 18px 0 9px 0;\n" +
98-
" }\n" +
99-
"}\n");
100-
out.println("</style>");
101-
out.println("</head");
102-
out.println("<body>");
103-
out.println("<h1>Ejemplo Servlet</h1>");
104-
out.println("<form action=\"/myServlet2\">\n" +
105-
" <label for=\"fname\">Nombre:</label><br>\n" +
106-
" <input type=\"text\" id=\"fname\" name=\"fname\" value=\"John\"><br>\n" +
107-
" <input type=\"submit\" value=\"Submit\">\n" +
108-
"</form> ");
109-
out.println("</body></html>");
22+
//MyObject obj = ... //build somehow
23+
//request.setAttribute("myObject", obj);
24+
RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/jsp/formulario.jsp");
25+
rd.forward(request, response);
11026
}
11127

11228
}
Lines changed: 5 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ejemplos.servlet.curso;
22

3+
import javax.servlet.RequestDispatcher;
34
import javax.servlet.ServletException;
45
import javax.servlet.annotation.WebServlet;
56
import javax.servlet.http.HttpServlet;
@@ -18,89 +19,10 @@ protected void doGet(HttpServletRequest request,
1819
PrintWriter out = response.getWriter();
1920

2021
// send HTML page to client
21-
out.println("<html>");
22-
out.println("<head><title>Ejemplo HTML desde Servlet</title>");
23-
out.println("<style>");
24-
out.println("body {\n" +
25-
" display: flex;\n" +
26-
" justify-content: center;\n" +
27-
" align-items: center;\n" +
28-
" min-height: 100vh;\n" +
29-
" background: #eceffc;\n" +
30-
"}\n" +
31-
"\n" +
32-
".btn {\n" +
33-
" padding: 8px 20px;\n" +
34-
" border-radius: 0;\n" +
35-
" overflow: hidden;\n" +
36-
"\n" +
37-
" &::before {\n" +
38-
" position: absolute;\n" +
39-
" content: \"\";\n" +
40-
" top: 0;\n" +
41-
" left: 0;\n" +
42-
" width: 100%;\n" +
43-
" height: 100%;\n" +
44-
" background: linear-gradient(\n" +
45-
" 120deg,\n" +
46-
" transparent,\n" +
47-
" var(--primary-color),\n" +
48-
" transparent\n" +
49-
" );\n" +
50-
" transform: translateX(-100%);\n" +
51-
" transition: 0.6s;\n" +
52-
" }\n" +
53-
"\n" +
54-
" &:hover {\n" +
55-
" background: transparent;\n" +
56-
" box-shadow: 0 0 20px 10px hsla(204, 70%, 53%, 0.5);\n" +
57-
"\n" +
58-
" &::before {\n" +
59-
" transform: translateX(100%);\n" +
60-
" }\n" +
61-
" }\n" +
62-
"}\n" +
63-
"\n" +
64-
".form-input-material {\n" +
65-
" --input-default-border-color: white;\n" +
66-
" --input-border-bottom-color: white;\n" +
67-
" \n" +
68-
" input {\n" +
69-
" color: white;\n" +
70-
" }\n" +
71-
"}\n" +
72-
"\n" +
73-
".login-form {\n" +
74-
" display: flex;\n" +
75-
" flex-direction: column;\n" +
76-
" align-items: center;\n" +
77-
" padding: 50px 40px;\n" +
78-
" color: white;\n" +
79-
" background: rgba(0, 0, 0, 0.8);\n" +
80-
" border-radius: 10px;\n" +
81-
" box-shadow: 0 0.4px 0.4px rgba(128, 128, 128, 0.109),\n" +
82-
" 0 1px 1px rgba(128, 128, 128, 0.155),\n" +
83-
" 0 2.1px 2.1px rgba(128, 128, 128, 0.195),\n" +
84-
" 0 4.4px 4.4px rgba(128, 128, 128, 0.241),\n" +
85-
" 0 12px 12px rgba(128, 128, 128, 0.35);\n" +
86-
"\n" +
87-
" h1 {\n" +
88-
" margin: 0 0 24px 0;\n" +
89-
" }\n" +
90-
"\n" +
91-
" .form-input-material {\n" +
92-
" margin: 12px 0;\n" +
93-
" }\n" +
94-
"\n" +
95-
" .btn {\n" +
96-
" width: 100%;\n" +
97-
" margin: 18px 0 9px 0;\n" +
98-
" }\n" +
99-
"}\n");
100-
out.println("</style>");
101-
out.println("</head>");
102-
out.println("<body>");
103-
out.println("<h1>Bienvenido/a " + request.getParameter("fname") + " !!</h1>");
22+
//MyObject obj = ... //build somehow
23+
request.setAttribute("valueFname", request.getParameter("fname"));
24+
RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/jsp/saludo.jsp");
25+
rd.forward(request, response);
10426
}
10527

10628
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head>
3+
<title>Servlet formulario saludo v1.3</title>
4+
<link rel="stylesheet" href="css/style.css" type="text/css"></link>
5+
</head>
6+
<body>
7+
<h1>Ejemplo Servlet</h1>
8+
<form action="/myServlet2">
9+
<label for="fname">Nombre:</label><br>
10+
<input type="text" id="fname" name="fname" value="John"><br>
11+
<input type="submit" value="Submit">
12+
</form>
13+
</body>
14+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head>
3+
<title>Pagina de saludo v1.3</title>
4+
<link rel="stylesheet" href="css/style.css" type="text/css"></link>
5+
</head>
6+
<body>
7+
<h1>Bienvenido/a ${valueFname} !! </h1>
8+
</body>
9+
</html>

src/main/webapp/css/style.css

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
body {
2+
display: flex;
3+
justify-content: center;
4+
align-items: center;
5+
min-height: 100vh;
6+
background: #eceffc;
7+
}
8+
9+
.btn {
10+
padding: 8px 20px;
11+
border-radius: 0;
12+
overflow: hidden;
13+
14+
&::before {
15+
position: absolute;
16+
content: "";
17+
top: 0;
18+
left: 0;
19+
width: 100%;
20+
height: 100%;
21+
background: linear-gradient(
22+
120deg,
23+
transparent,
24+
var(--primary-color),
25+
transparent
26+
);
27+
transform: translateX(-100%);
28+
transition: 0.6s;
29+
}
30+
31+
&:hover {
32+
background: transparent;
33+
box-shadow: 0 0 20px 10px hsla(204, 70%, 53%, 0.5);
34+
35+
&::before {\
36+
transform: translateX(100%);
37+
}
38+
}
39+
}
40+
41+
.form-input-material {
42+
--input-default-border-color: white;
43+
--input-border-bottom-color: white;
44+
45+
input {
46+
color: white;
47+
}
48+
}
49+
50+
.login-form {
51+
display: flex;
52+
flex-direction: column;
53+
align-items: center;
54+
padding: 50px 40px;
55+
color: white;
56+
background: rgba(0, 0, 0, 0.8);
57+
border-radius: 10px;
58+
box-shadow: 0 0.4px 0.4px rgba(128, 128, 128, 0.109),
59+
0 1px 1px rgba(128, 128, 128, 0.155),
60+
0 2.1px 2.1px rgba(128, 128, 128, 0.195),
61+
0 4.4px 4.4px rgba(128, 128, 128, 0.241),
62+
0 12px 12px rgba(128, 128, 128, 0.35);
63+
64+
h1 {
65+
margin: 0 0 24px 0;
66+
}
67+
68+
.form-input-material {
69+
margin: 12px 0;
70+
}
71+
.btn {
72+
width: 100%;
73+
margin: 18px 0 9px 0;
74+
}
75+
}

0 commit comments

Comments
 (0)