how can i overcome this compilation error? - eclipse

Actually i am new to eclipse and jdbc connections i tried to connect to hive database on my centos and am trying to perform queries on a table in hive database through the following code.And am facing compilation problem for this code.plz help me..
<%#page import="org.apache.hadoop.hive.jdbc.HiveDriver"%>
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# page import = "java.sql.*" %>
<%# page import = "java.math.*" %>
<%# page import = "java.util.Map.Entry"%>
<%
try {
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver").newInstance();
}
catch(ClassNotFoundException ex){
System.out.println("error:unable to load driver class");
System.exit(1);
}
%>
<!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>server side</title>
</head>
<body>
<%
Connection connection = DriverManager.getConnection("jdbc:hive://localhost:10000/nikhildb");
Statement statement = connection.createStatement();
String country_name = request.getParameter("country_name");
ResultSet rs = statement.executeQuery("Select * from population where country_name ='"+country_name+"'");
if(!rs.next()){
System.out.println("Sorry, no country exists");
}
else{
%>
i had some table details in html after else statement.
this is the photo copy of compilation error occured
plzz help me..!

Your HiveDriver is a packages - "org.apache.hadoop.hive.jdbc.HiveDriver resolves to a package", so the correct way to import it is:
<%#page import="org.apache.hadoop.hive.jdbc.HiveDriver.*"%>
I can't say, where and how many time you have to fix it, though.

Related

ClassNotFound Exception: org.postgresql.Driver from [Module "deployment.ValidateUser.war:main" from Service Module Loader]

I am trying to connect with postgre databse with jsp program using Eclipse IDE,
I am getting this error:
"java.lang.ClassNotFoundException: org.postgresql.Driver from [Module
"deployment.ValidateUser.war:main" from Service Module Loader]".
I had put the jar files required for my project even though i am getting classnotfound exception error.
<%#page import="com.uservalidation.FarwordNames"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<%-- Imports --%>
<%# page import="java.sql.*"%>
<%# page import="java.util.*"%>
<%# page import="javax.servlet.*" %>
<%# page import="javax.servlet.http.*" %>
<%-- HTTP header --%>
<%response.addHeader("Cache-Control","no-cache");
response.addHeader("Pragma","no-cache");
response.addHeader("Expires","0");
%>
<%-- Variables that will be written --%>
<%
String fname = request.getParameter("fname");
String mname = request.getParameter("mname");
String lname = request.getParameter("lname");
String dob = request.getParameter("dob");
String addr = request.getParameter("addr");
%>
<%-- Creating new staff account - writing --%>
<%
try{
Class.forName("org.postgresql.Driver");
String conURL= "jdbc:postgresql://192.168.1.157:5432/MIPSUITE_DEV";
Connection con = DriverManager.getConnection(conURL,"mipsuitedev01","mipsuitedev01");
Statement st = con.createStatement();
//int status = st.executeUpdate("insert into users(fname,mname,lname,dob,address) values('"+fname+"',"+mname+"','"+lname+"','"+dob+"','"+addr+"')");
/* if(status>0){
out.println("Update sucessful");
}
else{
out.println("Update unsuccessful");
} */
st.close();
con.close();
}
catch(Exception e){
out.println(e);
}
%>
</body>
</html>
It seems to be fixed the problem by removing all resteasy/jaxrs/jboss libraries from the WAR file's WEB-INF/lib/.
Put postgresql driver
jar files into WEB-INF/lib folder.
I think it's should be work for you.

jsp form selection not working

I have following jsp page, when i select MYAP_FORM i expect the hidden form to be displayed but it is not.
Right now i have only one form with display none, i will be adding more and based on the selection will display right one.
Any inputs why i dont see the corresponding form displayed ...
Thanks
<%# 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">
<%# page import="java.io.*"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%#taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="url">${pageContext.request.requestURL}</c:set>
<c:set var="baseURL" value="${fn:replace(url, pageContext.request.requestURI, pageContext.request.contextPath)}" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="${baseURL}/bootstrap/css/bootstrap.css">
<title>Testing</title>
</head>
<body>
<script src="${baseURL}/bootstrap/js/bootstrap.js"></script>
<form id="platform" class="container text-center">
<select id="myselect">
<option value="" selected="selected"></option>
<option value="MYAP_FORM">MYAP_FORM</option>
<option value="XYZ_FORM">XYZ_FORM</option>
</select>
</form>
<%
String file = application.getRealPath("/") + "xzyFiles.txt";
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String tmp;
out.println("<form class=\"container\" id=\"MYAP_FORM\" style=\"display:none\">");
while ((tmp = br.readLine()) != null) {
out.print("<label class=\"checkbox text-left\">");
out.print("<input type=\"checkbox\" id=\"" + tmp +"\" value=\"1\">" + tmp + "</BR>");
out.print("</label>");
}
fis.close();
out.println("<button class=\"btn btn-primary\">Submit</button>");
out.println("<button class=\"btn btn-primary\">Clear</button>");
out.println("</form>");
%>
<script>
$("#myselect").on("change", function() {
$("#" + $(this).val()).show();
})
</script>
</body>
</html>
JQuery Script was missing, once added it worked fine.

Create a simple Login page using jsp and session

I have created a simple login page in which user will give an username and password , and then it will be stored in session. After clicking on submit button it will show welcome user or the name. And if the user waits for few seconds then the session will expire and it automatically return back to the login page.
Here is my login page
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;
charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>login</title>
</head>
<body>
<h1><center>Give your login details</center></h1>
<form method="post" action="check.jsp">
Username:<input type="text" name="username" size="20" value="<%=user.getUser() %>" > <br>
Password:<input type="password" name="password" size="20" value=<%=user.getPassword() %> ><br>
<input type="submit">
</form>
</body>
</html>
now in check.jsp i am doing my checking part for username and password
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<jsp:setProperty name="user" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>login checking</title>
</head>
<body>
<%
String USER=user.getUsername();
int PASSWORD=user.getPassword();
if(USER.equals("abhirup"))
{
if(PASSWORD==54321)
{
pageContext.forward("display.jsp");
}
else
{
out.println("Wrong password");
pageContext.include("login.jsp");
}
pageContext.include("login.jsp");
}
%>
</body>
</html>
and then finally i am displaying it in display.jsp
<%# page import="java.io.*,java.util.*" page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session" ></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Display</title>
</head>
<body>
<% String title="Welcome : successful login";
out.println(title);%>
<h3><center>Your Name:Abhirup Parui</center></h3><br>
Username<%=user.getUsername()%><br>
<%session.setMaxInactiveInterval(20);
pageContext.include("login.jsp");
%>
</body>
</html>
and also this is my LoginUser.java file
package user;
public class LoginUser {
String username;
int password;
public void setUsername(String value)
{
username=value;
}
public void setPassword(int value)
{
password=value;
}
public String getUsername(){return username;}
public int getPassword(){return password;}
}
I am using Eclipse IDE and Tomcat server. Eclipse has shown not a single error in any of the pages but still when i run my login.jsp page.
I am getting this error on running login.jsp
i have followed this link
please help me to find my errors.
Update
I can successfully run my login page.
I am getting this error now, but could not figure out where is the error.
last part of the error is this
how to fix these error . help
Because you're trying to access login.jsp directly from the browser you have to move it out of the WEB-INF directory - files in WEB-INF are not publicly accessible. If you move login.jsp up one directory and enter http://localhost:8088/abhirup/login.jsp in your browser it should pull up the page. However, it is a fairly common practice to put jsp pages under WEB-INF/jsp or something similar and use a servlet to intercept and process requests and then have the servlet forward to the appropriate jsp page.
You have a syntax error on line 1, column 46 of display.jsp because you have the word page before your language declaration. Change this:
<%# page import="java.io.*,java.util.*" page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
to this:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
I also tried the same code and I found some error in two JSP files
My login.jsp corrected code is as given below:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;
charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# page import="user.LoginUser"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login page</title>
</head>
<body>
<h1><center>Give your login details</center></h1>
<form method="post" action="check.jsp">
User name:<input type="text" name="username" size="20" value="<%=user.getUsername() %>"><br>
Password:<input type="password" name="password" size="20" value="<%=user.getPassword()%>" ><br>
Submit <input type="submit">
</form>
</body>
</html>
Corrected check.jsp code is as follows:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%# page import="user.LoginUser"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session"></jsp:useBean>
<jsp:setProperty name="user" property="*"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login checking</title>
</head>
<body>
<%
String USER=user.getUsername();
String PASSWORD=user.getPassword();
if(USER.equals("admin"))
{
if(PASSWORD.equals("admin"))
{
pageContext.forward("display.jsp");
}
else
{
out.println("Wrong password");
pageContext.include("login.jsp");
}
pageContext.include("login.jsp");
}
%>
</body>
</html>
Corrected display.jsp code:
<%# page import="java.io.*,java.util.*" language="java" contentType="text/html;charset=ISO-8859-1"pageEncoding="ISO-8859-1"%>
<%# page import="user.LoginUser"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="user" class="user.LoginUser" scope="session" ></jsp:useBean>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Display</title>
</head>
<body>
<% String title="Welcome : Successful Login";
out.println(title);%>
<h3> <center> Your Name : Reneesh </center> </h3><br>
User name : <%=user.getUsername()%><br>
<%session.setMaxInactiveInterval(20);
%>
</body>
</html>
My Java file LoginUser.java corrected code is as follows:
package user;
public class LoginUser {
String username;
String password;
public void setUsername(String value)
{
username=value;
}
public void setPassword(String value)
{
password=value;
}
public String getUsername()
{
return username;
}
public String getPassword()
{
return password;
}
}
Kindly try with this code, I made some changes in the code by assigning String valuue for Password. I also used Eclipse juno IDE and Apache Tom Cat v 7.0 for running this Dynamic web project. Hope you will try and let me know if there is further error.

How do I create a redirect from two different urls redirect to just one URL? (see code below)

I want to create a redirect from two different urls redirect to just one URL. I hope this question has a simple answer, I've actually provided the sample code I'm using below & just wanted to know if I could add another URL to the code below maybe using an "else if" statement....Thanks for your help
<%# Language=VBScript %>
<%
servername = Request.ServerVariables("HTTP_HOST")
if trim(Request.ServerVariables("HTTP_HOST")) = "levi.com" or
trim(Request.ServerVariables("HTTP_HOST")) = "levis.com" then
url = "http://www.timoloud.com/"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", url
Response.End
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="Javascript">
function redirect() {
window.location.href = 'http://www.levi.com/timoloud.com';
}
</script>
</head>
<body onload="redirect();">
</body>
</html>
Using Select Case statement may be easier to doing this.
Select Case Request.ServerVariables("HTTP_HOST")
Case "levi.com", "levis.com", "other.com", "another.com"
url = "http://www.timoloud.com/"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", url
End Select
It's not very clear to me but i suppose you want something like this
<%# Language=VBScript %>
<%
servername = Request.ServerVariables("HTTP_HOST")
redirectedUrls = "/levi.com/levis.com/"
if instr(redirectedUrls,"/" & servername & "/") then
url = "http://www.timoloud.com/"
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", url
Response.End
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="Javascript">
function redirect() {
window.location.href = 'http://www.<%=servername%>/timoloud.com';
}
</script>
</head>
<body onload="redirect();">
</body>
</html>

Return UTF-8 encoding from an Action in Struts 2

I'm trying to output a list of strings to a jsp page using struts 2. The template file is something like this:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<s:iterator value="vars">
<p><s:property /></p>
</s:iterator>
</body>
</html>
The corresponding java action file is:
public class TestAction extends ActionSupport {
private static final long serialVersionUID = 1L;
List<String> vars = null;
public List<String> getVars() { return vars; }
public void setVars(List<String> vars) { this.vars = vars; }
#Override
public String doExecute() throws Exception {
vars = new ArrayList<String>();
vars.add("Users");
vars.add("Organizações");
vars.add("Eventos");
vars.add("Locais");
return SUCCESS;
}
}
The problem is that, the result is:
Users
Organizações
Eventos
Locais
(source code)
<p>Users</p>
<p>Organizações</p>
<p>Eventos</p>
<p>Locais</p>
which I believe it means that I'm receiving the strings encoded with something that's not UTF-8. Any ideas on how to solve this?
This is very late reply, but I want to update this to help, somebody who stuck with this bug. Add following lines to your jsp to resolve the issue.
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<s:property escapeHtml="false"/>
Depending on your version of struts 2
Older: (this is deprecated in newer versions)
<s:property escape="false"/>
Newer: (not sure which version this was introduced)
<s:property escapeHtml="false"/>