Commit 6703c9ff by OscarGonzalez97

se agregan ejemplos JSP

parent 808c1385
package com.roshka.bootcamp.MVC;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/mvc")
public class Controller extends HttpServlet {
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String url = "/index.html";
}
}
package com.roshka.bootcamp;
import com.roshka.bootcamp.bean.User;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/introJSP")
public class UserController extends HttpServlet {
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
User user = new User();
user.setNombre("Oscar");
user.setApellido("Gonzalez");
user.setEmail("ogonzalez@roshka.com");
request.setAttribute("usuario", user);
getServletContext()
.getRequestDispatcher("/ejemploEL.jsp")
.forward(request, response);
}
}
package com.roshka.bootcamp.bean;
import java.io.Serializable;
public class User implements Serializable {
private String nombre;
private String apellido;
private String email;
// getters y setters
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido() {
return apellido;
}
public void setApellido(String apellido) {
this.apellido = apellido;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
// constructor
public User() {
this.apellido = "";
this.nombre = "";
this.email = "";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Suma de 2 numeros</title>
</head>
<body>
<%
int num1 =Integer.parseInt( request.getParameter("number1"));
int num2 =Integer.parseInt( request.getParameter("number2"));
%>
La suma de <%=num1 %> y <%=num2 %> == <%=num1+num2 %>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="estilos/login.css"></link>
</head>
<body>
<h1>Usando JSP</h1>
<label> Nombre:</label>
<span>${usuario.nombre}</span>
<label> Apellido:</label>
<span>${usuario.apellido}</span>
<label> Email:</label>
<span>${usuario.email}</span>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Addition</title>
</head>
<body>
<form action="addition.jsp">
<h2>Enter the Numbers</h2><br/>
Number1: <input type="text" name="number1"/><br/>
Number2: <input type="text" name="number2"/><br/>
<input type="submit" name="submit"/>
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment