código se ejecute en los comentarios en Java

En este artículo, vamos a discutir sobre un simple truco en Java para ejecutar código escrito en los comentarios .
Hemos estudiado que los comentarios no se ejecuta nunca, pero hay un truco por el cual podemos burlarse de los amigos, mostrándoles un código se ejecuta es decir, escritos en los comentarios
. Esto se puede hacer usando un carácter Unicode porque secuencia de caracteres de escape java análisis sintáctico en el código fuente. Así class ello se utilizó,

/ u000d y rarr; de caracteres Unicode, se analiza como nueva línea

‘ n’
por java.

Aquí está una for programa de la misma,

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="com.includehelp.*, java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>CRUD</title>
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="container">
<div class="panel-primary">
<div class="panel-heading">
<h3 class="panel-title">CRUD OPERATIONS IN JSP with Bootstrap Design</h3>
</div>
<div class="panel-body">
<form action="action.jsp" class="form-horizontal" method="post">
<div class="form-group col-md-6">
<label class="control-label" for="UserID">USER ID </label>
<input type="text" id="UserID" class="form-control" name="UserID" placeholder="ENTER YOUR UserID" required="required">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<label for="email" class="control-label">EMAIL ID</label>
<input type="email" id="email" class="form-control" name="email" placeholder="ENTER YOUR EMAIL" required="required">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<label for="department" class="control-label">DEPARTMENT</label>
<select id="department" required="required" class="form-control" name="department">
<option value="">Select</option>
<option value="MARKETING">MARKETING</option>
<option value="TESTING">TESTING</option>
<option value="DEVELOPMENT">DEVELOPMENT</option>
<option value="TRAINING">TRAINING</option>
</select>
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<label for="phone" class="control-label">PHONE</label>
<input type="tel" id="phone" class="form-control" name="phone" placeholder="ENTER YOUR PHONE" required="required">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<button class="btn btn-success">REGISTER</button>
</div>
</form>
</div>
</div>
</div>
<%
Operations opObject = new Operations();
List<UserPOJO> list = new ArrayList();
list = opObject.getListUsers();
System.out.println(list.size());
if(!(list.isEmpty())){
%>
<table class="table bordered">
<thead><tr><th></th><th>USER ID</th><th>EMAIL</th><th>PHONE</th><th>DEPARTMENT</th></tr></thead>
<% for(UserPOJO p : list){%>
<tr><td><input type="radio" name="rdValues" id="rdId" value="<%=p.getUserid()+"~"+p.getEmail()+"~"+p.getDepartment()+"~"+p.getPhone()%>"></td><td><%=p.getUserid()%></td><td><%=p.getEmail()%></td><td><%=p.getPhone()%></td><td><%=p.getDepartment()%></td></tr>
<% }%>
</table>
<button class="btn btn-primary" name="edit" value="edit" onclick="editThis()">EDIT</button>
<button class ="btn btn-primary" name="delete" value="delete" onclick="deleteThis()">DELETE</button>
<%}
%>
<script>
function editThis(){
var edit;
edit = document.getElementsByName("rdValues");
var selVal="";
for(var c=0;c<edit.length;c++){
if(edit[c].checked == true){
selVal+=edit[c].value;
break;
}
}
window.location.href="edit.jsp?values="+selVal;
}
function deleteThis(){
var values;
values = document.getElementsByName("rdValues");
var selVal="";
for(var c=0;c<values.length;c++){
if(values[c].checked == true){
selVal+=values[c].value;
break;
}
}
window.location.href="delete.jsp?userid="+selVal;
}
</script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>

salida

package com.includehelp;
public class UserPOJO {
private String userid;
private String email;
private long phone;
private String department;
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public long getPhone() {
return phone;
}
public void setPhone(long phone) {
this.phone = phone;
}
public String getDepartment() {
return department;
}
public void setDepartment(String department) {
this.department = department;
}
}

El programa anterior será tratada como,

package com.includehelp;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
public class Operations implements OperationsInterface {
static String message ="";
@Override
public String save(UserPOJO uObject) {
int flag =0;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/MYDB","root","new_password");
PreparedStatement ps = con.prepareStatement("INSERT INTO USERDETAILS VALUES(?,?,?,?);");
ps.setString(1, uObject.getUserid());
ps.setString(2, uObject.getEmail());
ps.setString(3, uObject.getDepartment());
ps.setLong(4, uObject.getPhone());
flag = ps.executeUpdate();
if(flag!=0){
message ="Saved SuccessFully";
}
} catch (Exception e) {
System.out.println(e);
}
return message;
}
@Override
public List<UserPOJO> getListUsers() {
System.out.println("inside getlist");
List <UserPOJO> list = new ArrayList<UserPOJO>();
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/MYDB","root","new_password");
PreparedStatement ps = con.prepareStatement("SELECT * FROM USERDETAILS;");
ResultSet rs = ps.executeQuery();
while(rs.next()){
UserPOJO uObject = new UserPOJO();
uObject.setUserid(rs.getString(1));
uObject.setEmail(rs.getString(2));
uObject.setDepartment(rs.getString(3));
uObject.setPhone(rs.getLong(4));
list.add(uObject);
}
con.close();
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
public String Update(UserPOJO uObject){
int status=0;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/MYDB","root","new_password");
PreparedStatement ps = con.prepareStatement("UPDATE USERDETAILS SET EMAIL=?,DEPARTMENT=?,PHONE=? WHERE USERID=?;");
ps.setString(1, uObject.getEmail());
ps.setString(2, uObject.getDepartment());
ps.setLong(3, uObject.getPhone());
ps.setString(4, uObject.getUserid());
status = ps.executeUpdate();
if(status!=0){
message ="Updated SuccessFully";
}
} catch (Exception e) {
System.out.println(e);
}
return message;
}
public String deleteUser(String userid){
int status=0;
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/MYDB","root","new_password");
PreparedStatement ps = con.prepareStatement("DELETE FROM USERDETAILS WHERE USERID=?;");
ps.setString(1, userid);
status = ps.executeUpdate();
if(status!=0){
message ="Record Deleted SuccessFully";
}
} catch (Exception e) {
System.out.println(e);
}
return message;
}
}

Nota: esto sólo main trabajo los comentarios de una sola línea.

El siguiente comentario de varias líneas

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="com.includehelp.*, java.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>CRUD</title>
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<%
String userid = request.getParameter("UserID");
String email = request.getParameter("email");
String tel = request.getParameter("phone");
String department = request.getParameter("department");
long phone = Long.parseLong(tel);
UserPOJO uObject = new UserPOJO();
uObject.setUserid(userid);
uObject.setEmail(email);
uObject.setDepartment(department);
uObject.setPhone(phone);
Operations opObject = new Operations();
String message = opObject.save(uObject);%>
<%if(message!=null){%>
<jsp:include page="index.jsp"></jsp:include>
<% }
%>
</body>
</html>

no funcionará porque va a ser tratada como

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<%
String values = request.getParameter("values");
String split[] =values.split("~");
String userid = split[0];
String email =split[1];
String department = split[2];
String phone = split[3];
%>
<div class="container">
<div class="panel-primary">
<div class="panel-heading">
<h3 class="panel-title">CRUD OPERATIONS IN JSP with Bootstrap Design</h3>
</div>
<div class="panel-body">
<form action="update.jsp" class="form-horizontal" method="post">
<div class="form-group col-md-6">
<label class="control-label" for=UserID>USER ID</label>
USER NAME CANNOT BE MODIFIED
<input type="text" id="UserID" class="form-control" name="UserID" placeholder="ENTER YOUR USERID" readonly required="required" value="<%=userid%>">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<label for="email" class="control-label">EMAIL ID</label>
<input type="email" id="email" value ="<%=email%>"class="form-control" name="email" placeholder="ENTER YOUR EMAIL" required="required">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<label for="department" class="control-label">DEPARTMENT</label>
<select id="department" required="required" class="form-control" name="department">
<option value="">Select</option>
<option value="MARKETING">MARKETING</option>
<option value="TESTING">TESTING</option>
<option value="DEVELOPMENT">DEVELOPMENT</option>
<option value="TRAINING">TRAINING</option>
</select>
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<label for="phone" class="control-label">PHONE</label>
<input type="tel" id="phone" class="form-control" name="phone" placeholder="ENTER YOUR PHONE" value ="<%=phone %>" required="required">
</div>
<div class="clearfix"></div>
<div class="form-group col-md-6">
<button class="btn btn-success">UPDATE</button>
</div>
</form>
</div>
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>

Así que nada conseguirá impresa.

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *