HTTP Status 500 - org.apache.jasper.JasperException: java.lang.NullPointerException - java

I deployed my project on the production server and getting the below error.
It's a live project so , after getting error i replaced this with previous version that was running fine but now that is also throwing the same error.Please suggest me what could be the problem ?
error:
HTTP Status 500 - org.apache.jasper.JasperException: java.lang.NullPointerException
--------------------------------------------------------------------------------
type Exception report
message org.apache.jasper.JasperException: java.lang.NullPointerException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:412)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:709)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:680)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:821)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.LPSSuppIndex_jsp._jspService(LPSSuppIndex_jsp.java:393)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause
java.lang.NullPointerException
org.apache.jsp.error_jsp._jspService(error_jsp.java:124)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:709)
org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:680)
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:821)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:794)
org.apache.jsp.LPSSuppIndex_jsp._jspService(LPSSuppIndex_jsp.java:393)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.36 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.36
IndexPage.jsp :
<%# page errorPage="error.jsp"%>
<%# page import="java.util.*" %>
<%# page import = "jdbc.RetrieveLangList,lang.MessageGetter" %>
<%!
HashMap<String, String> langListMap = new HashMap<String, String>();
%>
<%
//Retrieving language MAP
RetrieveLangList objList = new RetrieveLangList();
langListMap = objList.LangList();
Set s = langListMap.entrySet(); // Get hashmap in Set interface to get key and value
Iterator it = s.iterator(); // Move next key and value of HashMap by iterator
String suppLang = "en_US";
suppLang = request.getParameter("suppLanguage");
if (suppLang == null || suppLang.equalsIgnoreCase(""))
suppLang = "en_US";
%>
<html>
<HEAD>
<TITLE> Welcome to </TITLE>
<link rel="SHORTCUT ICON" href="image/H.ico"/>
<LINK href="image/css/Rcontent.css" type="text/css" rel="stylesheet">
</HEAD>
<script language="JavaScript">
function loadPage(list)
{
location.href=list.options[list.selectedIndex].value;
}
</script>
<SCRIPT language="Javascript">
function ValidateForm()
{
//Supplier Number Validation
var supp_number =document.loginForm.uname;
if((supp_number.value=="su")||(supp_number.value=="SU"))
{
return true;
}
var stripped = supp_number.value.replace(/[\(\)\.\-\ ]/g, '');
if((supp_number.value==null)||(supp_number.value==""))
{
alert("<%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "Enter_User_ID")%>");
supp_number.focus();
return false;
}
else if (isNaN(parseInt(stripped))) {
alert("<%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "Invalid_User_ID")%>");
supp_number.focus();
return false;
}
//Password Validation
var supp_pass =document.loginForm.pass;
if((supp_pass.value==null)||(supp_pass.value==""))
{
alert("<%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "Enter_Password")%>");
//alert("Please Enter Password");
supp_pass.focus();
return false;
}
return true;
}
</SCRIPT>
<BODY bgcolor="#C7CACF">
<center>
<table border = "0" bordercolor = "black" style="background-image:url('image/backgroundIndex.jpg');background-repeat:no-repeat" width="1000" HEIGHT = "700" >
<tr height = "60">
<td> </td>
<td> </td>
<td colspan="2">
<form name="form1" >
<TABLE border="0" width = "610">
<TR>
<td width="300" align="right" height="40">
<select name="file" size="1" onchange="loadPage(this.form.elements[0])" target="_parent._top" onmouseclick="this.focus()" style="background-color: #ffffff;width:150px;"> <!-- This is language selection box -->
<%
while (it.hasNext())
{
Map.Entry m = (Map.Entry) it.next(); // key=value separator this by Map.Entry to get key and value
//System.out.println("value : "+m.getValue()+" key : "+m.getKey());
if(suppLang.equals(m.getKey()))
{
%>
<option value="LPSSuppIndex.jsp?suppLanguage=<%= m.getKey()%>" selected="selected"><%= m.getValue()%></option>
<%
}
else
{
%>
<option value="LPSSuppIndex.jsp?suppLanguage=<%= m.getKey()%>"><%= m.getValue()%></option>
<%
}
}
%>
</select>
</td>
<td width = "300px" align="right"><font color="#73767B" size="2"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "contact")%></font><font color="#73767B"><B> |</B></font><font color="#73767B" size="2"> <%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "imprint_legel_issue")%></font><font color="#73767B"><B> | </B></font><font color="#73767B" size="2"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "sitemap")%></font></td>
</TR>
<TR height="12px">
<TD colspan="2"> </TD>
</TR>
</TABLE>
</form>
</td>
</tr>
<tr>
<td height = "240px" valign="top">
<TABLE border="0" width = "195">
<TR>
<TD height="40" width="155" align="left"><div style="position:relative;left: 20px;"><font color="#73767B" size="3"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "home")%></font></div></TD>
</TR>
<TR>
<TD height="37" align="left"><div style="position:relative;left: 20px;"><font color="#73767B"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "contact")%></font></div></TD>
</TR>
<TR>
<TD height="35" align="left"><div style="position:relative;left: 20px;"><font color="#73767B" size="3"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "log_in")%></font></div></TD>
</TR>
<TR>
<TD height="34" align="left"> <font color="white" style="font-family:Arial, Helvetica, sans-serif;font-size: 10pt; font-weight: bold"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "tportal")%></font></TD>
</TR>
<TR>
<TD height = "32" align="center"> </TD>
</TR>
<TR>
<TD height = "43px" colspan="2" align="center"> </TD>
</TR>
</TABLE>
</td>
<td colspan="2"> </td>
<td rowspan="3" valign="top">
<table border="0px" >
<tr height="139px"><td> </td><td> </td></tr>
<tr height="431px">
<td valign="top" width="8px"><div class="vertical-line" style="position:relative;left:27px;top:0px;"></div></td>
<td valign="top">
<!-- START RIGHT CONTENT -->
<DIV class="cntr_cnt_gradbox" style="position: relative;left: 15px;top: -5px;">
<DIV class="cntr_head"><font size="2%"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "PDF_download")%> </font></DIV>
<DIV class="cntr_cnt_gradbox_inner">
<DIV class="cntr_frame" style="height: 60px;">
<DIV style="FLOAT: left;height: 50px;" >
<IMG src="image/PDF_Thumbnail_50x50.gif" border="0">
</DIV>
<DIV class="cntr_dl_cnt" style="MARGIN-LEFT: 55px;">
<A class="cntr_lnk" href="PDF/User Maner_EN.pdf" target="_blank"><font color="#73767B" size="2%"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "manual_en")%></font></A>
</DIV>
<BR class="clr">
</DIV>
<BR class="clr">
<DIV class="cntr_frame" style="height: 60px;">
<DIV style="FLOAT: left;height: 50px;" >
<IMG src="image/PDF_Thumbnail_50x50.gif" border="0">
</DIV>
<DIV class="cntr_dl_cnt" style="MARGIN-LEFT: 55px;">
<A class="cntr_lnk" href="PDF/Benutzerhl Printer_DE.pdf" target="_blank"><font color="#73767B" size="2%"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "manual_de")%></font></A>
</DIV>
<BR class="clr">
</DIV>
<BR class="clr">
<DIV class="cntr_frame" style="height: 60px;">
<DIV style="FLOAT: left;height: 50px;" >
<IMG src="image/PDF_Thumbnail_50x50.gif" border="0">
</DIV>
<DIV class="cntr_dl_cnt" style="MARGIN-LEFT: 55px;">
<A class="cntr_lnk" href="PDF/Print_Specification.pdf" target="_blank" title="<%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "printHelp_tip")%>"><font color="#73767B" size="2%"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "printHelp")%></font></A>
</DIV>
<BR class="clr">
</DIV>
<DIV class="cntr_frame1" style="height: 30px;">
<div style="margin-left: 30px;"> <A class="cntr_lnk" href="PDF/quick_guide_en.pdf" target="_blank"><font color="#73767B" size="2%"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "one_point_lessons")%> - EN</font></A></div>
</DIV>
<DIV class="cntr_frame1" style="height: 30px;">
<div style="margin-left: 30px;"> <A class="cntr_lnk" href="PDF/quick_guide_de.pdf" target="_blank"><font color="#73767B" size="2%"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "one_point_lessons")%> - DE</font></A></div>
</DIV>
<DIV style="height: 30px;vertical-align: middle;">
<div style="margin-left: 30px;"> <A class="cntr_lnk" href="PDF/FAQ.pdf" target="_blank"><font color="#73767B" size="2%">FAQ</font></A></div>
</DIV>
</DIV>
</DIV>
</td>
</tr>
</table>
</td>
</tr>
<tr height = "210">
<td> </td>
<td> </td>
<td>
<form method="post" name="loginForm" action="./loginServlet" onsubmit="return ValidateForm()">
<input type="hidden" name="selectedLang" value="<%=suppLang%>" >
<TABLE border="0" bordercolor="black" width="370">
<tr><td rowspan="6" width = "30"> </td></tr>
<TR height="45">
<td width="110" ><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "user_id")%> : </td><!-- This is Supplier Number(User ID) entry field. -->
<td width="230" align="center"><input type="text" size="25" name="uname" style="border-color: #529DFA;" maxlength="10"></td>
</TR>
<TR>
<td height="45"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "Password")%> : </td><!-- This is Password entry field. -->
<td align="center"><input type="password" size="25" name="pass" style="border-color: #529DFA;"></td>
</TR>
<TR height="40">
<td> </td>
<td align ="center" height="40"><%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "forget_password")%>
</td>
</TR>
<TR>
<td height="40" align="right"><input type="Submit" value="<%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "log_in")%>" /> </td>
<td align="center"><input type="button" onClick="location.href='register/suppRegistration.jsp?selectedLang=<%=suppLang%>'" value="<%=MessageGetter.getMessage("lang.MessagesBundle", suppLang, "new_user")%>" /></td>
</TR>
</TABLE></form>
</td>
</tr>
<tr height = "114">
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td width = "200"> </td>
<td width="170"> </td>
<td width="380"> </td>
<td width="230" align="center"> </td>
</tr>
</table>
</center>
</BODY>
</HTML>

In Tomcat a .java and .class file will be created for every jsp files with in the application and the same can be found from the path below,
Apache-Tomcat\work\Catalina\localhost\'ApplicationName'\org\apache\jsp\index_jsp.java
In your case the jsp name is error.jsp so the path should be something like below
Apache-Tomcat\work\Catalina\localhost\'ApplicationName'\org\apache\jsp\error_jsp.java in line no 124 you are trying to access a null object which results in null pointer exception.

NullPointerException with JSP can also happen if:
A getter returns a non-public inner class.
This code will fail if you remove Getters's access modifier or make it private or protected.
JAVA:
package com.myPackage;
public class MyClass{
//: Must be public or you will get:
//: org.apache.jasper.JasperException:
//: java.lang.NullPointerException
public class Getters{
public String
myProperty(){ return(my_property); }
};;
//: JSP EL can only access functions:
private Getters _get;
public Getters get(){ return _get; }
private String
my_property;
public MyClass(String my_property){
super();
this.my_property = my_property;
_get = new Getters();
};;
};;
JSP
<%# taglib uri ="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# page import="com.myPackage.MyClass" %>
<%
MyClass inst = new MyClass("[PROP_VALUE]");
pageContext.setAttribute("my_inst", inst );
%><html lang="en"><body>
${ my_inst.get().myProperty() }
</body></html>

Related

Non English Data Input From Java Web Application in Netbeans 8.0.2

My Connection String
Class.forName("com.mysql.jdbc.Driver");
conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/exam_system?useSSL=false&useUnicode=true&characterEncoding=utf8","root","Password");
My JSP File
<%#page import="java.util.ArrayList"%>
<jsp:useBean id="pDAO" class="myPackage.DatabaseClass" scope="page"/>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style-backend.css">
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="utf-8" >
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<label Style="color: black"> ছন্দে</label>
<input type="hidden" name="pgprt" value="4">
<select name="coursename" class="text">
<%
ArrayList list1=pDAO.getAllCourses();
for(int i=0;i<list1.size();i=i+2){
%>
<option value="<%=list1.get(i)%>"><%=list1.get(i)%></option>
<%
}
%>
</select>
<input type="submit" value="Show" class="form-button">
</form>
</div>
<div class="panel form-style-6" style="max-width: 420!important;float: right">
<form action="controller.jsp" >
<div class="title">Add New Question</div>
<table Style="color: black;font-color: black">
<tr>
<td><label Style="color: black">Course Name</label></td>
<td colspan="3">
<select name="coursename" class="text">
<%
ArrayList list=pDAO.getAllCourses();
for(int i=0;i<list.size();i=i+2){
%>
<option value="<%=list.get(i)%>"><%=list.get(i)%></option>
<%
} request.setCharacterEncoding("UTF-8");
%>
</select>
</td>
</tr>
<tr>
<td><label Style="color: black">Your Question:</label></td>
<td colspan="4"><input type="text" name="question" class="text" placeholder="Type your question here" style="width: 420px;" ></td><br>
</tr>
<tr>
<td><label Style="color: black">Options</label></td>
<td><input type="text" name="opt1" class="text" placeholder="First Option" style="width: 130px;" ></td>
<td><input type="text" name="opt2" class="text" placeholder="Second Option" style="width: 130px;" ></td>
<td><input type="text" name="opt3" class="text" placeholder="Third Option" style="width: 130px;" ></td>
<td><input type="text" name="opt4" class="text" placeholder="Fourth Option" style="width: 130px;" ></td>
</tr>
<tr>
<td><label>Correct Answer</label></td>
<td colspan="4"><center><input type="text" name="correct" class="text" placeholder="Correct Answer" style="width: 130px;" ></center></td>
<tr>
<td colspan="5"><input type="hidden" name="page" value="questions">
<input type="hidden" name="operation" value="addnew">
<center><input type="submit" class="form-button" value="Add" name="submit"></center></td>
When Inputting Non-English Data It is Not Inserting Correctly in MySQL Database. But
I changed Database Pattern And Test By Passing Non-English Data In String And It Works Perfectly.
INSERT INTO `exam_system`.`contact`
(`Name`,
`Email`,
`Message`)
VALUES
('<{Name:fsfsd }>',
'<{Email:sdfsdf }>',
'<{Message: 1. চর্যাপদ কোন ছন্দে লেখা? }');
Before Answering I tried
Net Bean Font Change
Tried Change String Data To Byte
And Rest
Change Are in the symbol Code.
When Accepting Parameter or User Value Convert That Value Into Char .
String crr=request.getParameter("correct");
byte[] bytesCrr = crr.getBytes(StandardCharsets.ISO_8859_1);
crr = new String(bytesCrr, StandardCharsets.UTF_8);

Using java.net.URLConnection to fetch data in html fetching only html code and not the actual data

Using java.net.URLConnection to fetch data from html is not fetching the actual data but only the html code.
Since the html is generating data dynamically the core html code doesn't have the data that is being displayed on the html.
Is there any other means of fetching the data being displayed on the html page?
My code goes like this:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class Example {
public static void main(String[] args) throws IOException {
System.setProperty("java.net.useSystemProxies", "true");
// Make a URL to the web page
URL url = new URL("https://rci-dtengine.rnd.ki.sw.ericsson.se/root//proj/cpptemp/jcat-cpp/DI/megatron/DT/INT_PA284/20170331_152720/20170331_152723/index.html");
// Get the input stream through URL Connection
URLConnection con = url.openConnection();
InputStream is =con.getInputStream();
// Once you have the Input Stream, it's just plain old Java IO stuff.
// For this case, since you are interested in getting plain-text web page
// I'll use a reader and output the text content to System.out.
// For binary content, it's better to directly read the bytes from stream and write
// to the target file.
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = null;
// read each line and write to System.out
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
}
Output:
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="img/jcat_m3.png"/>
<title>JCAT Test Report</title>
<link rel="stylesheet" type="text/css" href="css/jquery.fancybox.css" />
<link rel="stylesheet" type="text/css" href="css/top.css" media="screen" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui.min.css" />
<link rel="stylesheet" type="text/css" href="css/testsuite.css" />
<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/jquery-ui.min.js"></script>
<script src="js/jquery.fancybox.pack.js"></script>
<script src="js/jquery.storage.js"></script>
<script src="js/stupidtable.min.js"></script>
<script src="js/common.js"></script>
<script src="js/top.js"></script>
<script src="js/testsuite.js"></script>
<script>
window.onerror = function () {
alert("Failed to load data files as the format is corrupt!");
};
function receiveMessage(event) {
if (event.data !== "reload from settings") {
return;
}
window.location.reload();
}
window.addEventListener("message", receiveMessage, false);
</script>
<script src="json/suite.data.js"></script>
<script src="json/top.data.js"></script>
<script src="json/bulletin.message.data.js"></script>
</head>
<body>
<div class='top'></div>
<div id="bulletin">
<div id="bulletinBar">
<img id="bulletinSwitch"></img>
<span id="bulletinHint" style="display:none">hide bulletin</span>
</div>
<div id="bulletinFrame" class="ui-widget-content">
<div id="bulletinContent"></div>
</div>
</div>
<div id="autoRefresh">
<span id="refreshCountDown" style="display:none"></span>
<input id='autoRefreshBtn' type='button' value='enable auto refresh'></input>
</div>
<div id="content">
<div id="sumBlock">
<h3>Report Summary</h3>
<table id="suiteInfo" summary="Suite summary information">
<tbody>
<tr>
<td width="130px">Suite name:</td>
<td id="suiteName"></td>
</tr>
<tr>
<td>Run by:</td>
<td id="runBy"></td>
</tr>
<tr>
<td>Time started:</td>
<td id="startTime" class="timestamp"></td>
</tr>
<tr>
<td>Time finished:</td>
<td id="endTime" class="timestamp"></td>
</tr>
<tr>
<td>Duration:</td>
<td id="duration"></td>
</tr>
</tbody>
</table>
</div>
<div id="staBlock">
<h3>Statistics</h3>
<table id="statistics" summary="Suite statistic">
<tbody>
<tr>
<td width="100px">Passed TCs:</td>
<td id="tcPassed" width="50px"></td>
<td width="120px">Passed configs:</td>
<td id="configTcPassed" width="50px"></td>
</tr>
<tr>
<td>Failed TCs:</td>
<td id="tcFailed"></td>
<td >Failed configs:</td>
<td id="configTcFailed"></td>
</tr>
<tr>
<td>Error TCs:</td>
<td id="tcError"></td>
<td>Error configs:</td>
<td id="configTcError"></td>
</tr>
<tr>
<td>Skipped TCs:</td>
<td id="tcSkipped"></td>
<td>Skipped configs:</td>
<td id="configTcSkipped"></td>
</tr>
<tr>
<td>Excluded TCs:</td>
<td id="tcExcluded"></td>
<td>Executed configs:</td>
<td id="configTcRun"></td>
</tr>
<tr>
<td>Inconclusive TCs:</td>
<td id="tcInconclusive"></td>
<td></td>
<td></td>
</tr>
<tr>
<td>Executed TCs:</td>
<td id="tcRun"></td>
<td></td>
<td></td>
</tr>
<tr>
<td>UnExecuted TCs:</td>
<td id="tcNotRun"></td>
<td>TCs & configs:</td>
<td id="tcTotalRun"></td>
</tr>
</tbody>
</table>
</div>
<div id="testCases">
<input placeholder="Search..." type="text" id="filterText" maxlength="200" style="margin-left:5px;"/>
<div id='viewSwitch' style='display:none'>
| <span id="nestedFunc" style='display:none'> Show Nested Suites<input id='nestedSwitch' onchange="switchSuiteTable(this)" type="checkbox" value="Nested"></span>
<span id="groupedFunc" style='display:none'> Show Grouped Suite<input id='groupedSwitch' onchange="switchSuiteTable(this)" type="checkbox" value="Grouped"></span>
Auto-unfold Errors<input id='autoUnfold' onchange="setAutoUnfold()" type="checkbox" value="autoUnfold" checked="checked">
<input id="unfoldFunc" type="button" value="Unfold" onclick="$('tr.folded').click()">
<input id="foldFunc" type="button" value="Fold" onclick="$('tr.unfolded').click()">
</div>
| <span id="filter_icondown" style="color: #99cc00">&#9658</span> <span id="filter_iconright" style="color: #99cc00; display: none">&#9660</span>
<a id="filterHide" href="javascript:hideUnhideTable('filter')">Filters</a>
<div id="jcat_label">
| <span id="label_text">Labels:</span>
<select id="label_select">
</select>
</div>
<table id="filter" style="display: none;">
<tr>
<td width="120px">Passed TCs/configs:</td>
<td width="50px"><a id="label_passed" href="javascript:hideUnhideRows('passed')">Hide</a></td>
<td width="160px">Skipped TCs/configs:</td>
<td width="50px"><a id="label_skipped" href="javascript:hideUnhideRows('skipped')">Hide</a></td>
<td width="160px">All testcases:</td>
<td width="50px"><a id="label_testcases" href="javascript:hideUnhideRows('testcases')">Hide</a></td>
</tr>
<tr>
<td>Failed TCs/configs:</td>
<td><a id="label_failed" href="javascript:hideUnhideRows('failed')">Hide</a></td>
<td>Excluded TCs/configs:</td>
<td><a id="label_excluded" href="javascript:hideUnhideRows('excluded')">Hide</a></td>
<td>All configuration methods:</td>
<td><a id="label_cfgs" href="javascript:hideUnhideRows('cfgs')">Hide</a></td>
</tr>
<tr>
<td>Error TCs/configs:</td>
<td><a id="label_error" href="javascript:hideUnhideRows('error')">Hide</a></td>
<td>Inconclusive TCs/configs:</td>
<td><a id="label_inconc" href="javascript:hideUnhideRows('inconc')">Hide</a></td>
<td>All reruned testcases:</td>
<td><a id="label_rerun" href="javascript:hideUnhideRows('rerun')">Show</a></td>
</tr>
</table>
<table id="suiteTable" class='suite'>
<thead>
<tr>
<th data-sort="int" id="tcIndex" style="display:none">Index</th>
<th data-sort="string">ID</th>
<th data-sort="string">Name</th>
<th data-sort="string">Type</th>
<th data-sort="string">Heading</th>
<th data-sort="int">State</th>
<th data-sort="string">Additional Result Info</th>
<th data-sort="string" style="display:none;">Start Time</th>
<th data-sort="string" style="display:none;">End Time</th>
<th data-sort="string">Duration</th>
<th data-sort="string">Fetched Logs</th>
<th data-sort="string">Labels</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="nestedTable" class='suite Nested' style="display:none">
<thead>
<tr>
<th id="tcIndex" style="display:none">Index</th>
<th>ID</th>
<th>Name</th>
<th>Type</th>
<th>Heading</th>
<th>State</th>
<th>Additional Result Info</th>
<th style="display:none;">Start Time</th>
<th style="display:none;">End Time</th>
<th>Duration</th>
<th>Fetched Logs</th>
<th>Labels</th>
</tr>
</thead>
<tbody></tbody>
</table>
<table id="groupedTable" class='suite Grouped' style="display:none">
<thead>
<tr>
<th id="tcIndex" style="display:none">Index</th>
<th>ID</th>
<th>Name</th>
<th>Type</th>
<th>Heading</th>
<th>State</th>
<th>Additional Result Info</th>
<th style="display:none;">Start Time</th>
<th style="display:none;">End Time</th>
<th>Duration</th>
<th>Fetched Logs</th>
<th>Labels</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</body>
</html>
The only way to know the underlying API is if the site itself makes that information public.
As for loading the page, you’ll need a container capable of loading the page and executing its JavaScript; the WebView class of JavaFX is one such container. Every WebView has an associated WebEngine which provides the loaded page as an XML Document (even if the original content was not XHTML); you can use XPath on that Document to extract the text of the relevant <td> elements.

Selenium- WebDriver identifying Td value element which is inside the input tag

I am trying to identify the td value, the thing is inside TD i have input tag and i need to identify the value. My Td tag looks like below. I need to identify and get the value 4/11/2016. Trying to add the full source code
<div id="accountsSectionBottomContainer" class="acctBottom" default-path="/ui/app.php/AccountsBottomPane/21/acct_glance">
<div>
<div class="accountsModPLSQLReturn" data-aria-plsql-root="/ui/mod_plsql.php/aria/csrtools/" data-aria-plsql-url="dashboard_plan.plan_inst_unit_inst_dtls">
<div class="workbook_tabname">Accounts</div>
<script language="JavaScript" type="text/javascript"> self.focus(); </script>
<div id="account-name">
<style type="text/css"> .color-block dl { background-color: #F8F8FF; margin: 0; padding: 1em; } .white-block dl { font-size: 1.1em; margin: 0; padding: 1em; } .static-block dt { float: left; font-size: 1.1em; font-weight: bold; margin: 0; padding: 0; width: 300px; } .static-block dd { font-size: 1.1em; margin: 0 0 0 225px; padding: 0 0 5px 15px; } </style>
<script language="javascript" type="text/javascript"> $('.trgprdval').trigger('change'); var inFulfilmentStartDate_cal = new calendar3(document.main.inFulfillmentDate, "MM/DD/YYYY"); inFulfilmentStartDate_cal.year_scroll = true; inFulfilmentStartDate_cal.time_comp = false; function myCdidFunction() { var newCDID = document.getElementById('inClientDefinedIdentifier').value; document.getElementById('inNewCdid').value = newCDID; } function copyRadioVal(inputValue, origVal, inputName, name) { var hiddenValues = document.getElementsByClassName(name); console.log(inputName); console.log(name); console.log(document.getElementById(inputName)); x = document.getElementById(inputName).checked; if (x==true) { $("#"+origVal).val(inputValue); } } function copyCheckboxVal(inputValue, origVal, inputName, inPrimacyNo, inputId) { var x = document.getElementById(inputName).checked; if (x==true) { document.getElementById(origVal).value = inputValue; } if (x==false) { document.getElementById(origVal).value = ""; } var inputType = inPrimacyNo.concat(inputId); document.getElementById(inputType).value = inPrimacyNo; } function joinSelectVal(newInputName, oldInputId) { var selectval = document.forms["main"][oldInputId]; var selectedList = []; for (var i = 0; i < selectval.length; i++) { if (selectval[i].selected) { selectedList.push(selectval[i].value); } } var checkedStr = Array.join(selectedList, "~"); if (checkedStr.length == 0) { checkedStr = "NO#VALUE"; } document.getElementById(newInputName).value = checkedStr; } function validateInputsAndSubmit(button) { var valSuppFields = validateAcctSuppFields('.accountsForm'); if(!valSuppFields['isValid']) { alert(valSuppFields['errorMsg']); return false; } lockAndSubmitForm(button); } </script>
<div class="color-block">
<div class="white-block">
<form class="accountsForm" name="main" method="post" action="/ui/mod_plsql.php/aria/csrtools/dashboard_plan_m.plan_unit_instance_save_m" onsubmit="return false;">
<font size="3">
<br/>
<br/>
<table class="data-table clear-both" cellspacing="0">
<colgroup>
<tbody>
<tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089723</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089723" name="INSERVICES[0][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[0][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[0][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089723" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[0][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089726</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089726" name="INSERVICES[1][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[1][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[1][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089726" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[1][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089727</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089727" name="INSERVICES[2][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[2][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[2][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089727" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[2][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089730</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089730" name="INSERVICES[3][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[3][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[3][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089730" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[3][inFulfillmentDate]"/>
</td>
</tr>
<tr class="dataRow1 even">
<td valign="top" style="text-align: left;">
<td valign="top" style="text-align: left;">10089747</td>
<td valign="top" style="text-align: left;">Yes</td>
<td valign="top" style="text-align: left;">Invoiced</td>
<td valign="top" style="text-align: left;">
<input type="hidden" value="10089747" name="INSERVICES[4][inServiceNo]"/>
<input type="hidden" value="1" name="INSERVICES[4][inFulfillmentStatus]"/>
<input type="hidden" value="1" name="INSERVICES[4][inFulfillmentBasedInd]"/>
<input id="inFulfillmentDate10089747" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[4][inFulfillmentDate]"/>
</td>
</tr>
</tbody>
</table>
<br/>
<br/>
<font size="3">
<br/>
<br/>
<table class="simple" cellspacing="0">
<input type="hidden" value="8179" name="inPlanNo"/>
<input type="hidden" value="4066308" name="inPlanUnitInstanceNo"/>
<input id="inNewCdid" type="hidden" name="inClientDefinedIdentifier"/>
<input type="hidden" value="MasterPlan" name="inSelectedPlan"/>
<input type="hidden" value="19328197" name="inPlanInstanceNo"/>
<div class="form-buttons">
<input type="hidden" value="AAAAAAUJTTz9lWKS_TgqUANHCenOnmxH2IQHclhl2zoruTE55z7CFHIdaAAJNyGlNLLnb5f-97HVxpFchLgkkTjIFz9d_I_sKfI7EQd83gmsfyFtQA==" name="as_sfid"/>
<input type="hidden" value="yli8W38Xf7v_849HentO" name="as_fid"/>
</form>
</div>
</div>
</div>
<input id="inFulfillmentDate10089723" type="text" readonly="readonly" value="4/11/2016" name="INSERVICES[0][inFulfillmentDate]"/>
</td>
Hi in case you want to identify value="4/11/2016" you can directly use
in case of dynamic id plz use like
MyDynamicID = "//*[starts-with(#id,'inFulfillmentDate')]"
String value = driver.findElement(By.id(MyDynamicID )).getText();
now print string in the console
UPADTE
// our id = inFulfillmentDate pattern
List<WebElement> myDate = driver.findElements(By.xpath("//*[starts-with(#id,'inFulfillmentDate')]"));
System.out.println(myDate.size());
// now print all value
for(int i=0;i<myDate.size();i++){
System.out.println("value is : " +myDate.get(i).getAttribute("value"));
}
Belwo is the console output
6
value is : 4/11/2016
value is : 4/11/2016
value is : 4/11/2016
value is : 4/11/2016
value is : 4/11/2016
value is : 4/11/2016

Neither BindingResult nor plain target object for bean name available as request attribute (Spring MVC)

Please help me. Im trying to use 2 Forms on 1 jsp. The first Form works just fine. When i try to submit the second form i get the IllegalStateException. I have already read a lot of things about this problem, but nothing could solve my current problem.
Form:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<head>
<%# include file="../views/common/imports.jsp" %>
<title>MARC</title>
</head>
<body onload="togglePieLines()">
<%# include file="../views/common/header.jsp"%>
<br>
<br>
<div class="standard-form">
<form:form commandName="unit" method="post" action="units" class="uk-form" id="unitForm">
<!-- Allgemeine Informationen -->
<table class="uk-table uk-table-condensed uk-text-small">
<thead>
<tr>
<th><spring:message code="units.generalInformation"/></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="uk-width-1-1 td-form-row"><spring:message code="units.id"/> * <form:errors path="unitId" class="uk-badge uk-badge-warning"/></td>
<td class="uk-width-1-1"><form:input path="unitId" class="uk-form-width-medium" /></td>
</tr>
<tr>
<td><spring:message code="units.name"/> * <form:errors path="name" class="uk-badge uk-badge-warning"/></td>
<td>
<form:input path="name" class="uk-form-width-medium" />
</td>
</tr>
<tr>
<td><spring:message code="units.country"/> * <form:errors path="country" class="uk-badge uk-badge-warning"/></td>
<td>
<div class="uk-form-row">
<form:select path="country" items="${countryList}" class="uk-form-width-medium" />
</div>
</td>
</tr>
<tr>
<td><spring:message code="units.bu"/></td>
<td><form:input path="bu" class="uk-form-width-medium" /></td>
</tr>
<tr>
<td><spring:message code="units.pie"/></td>
<td><form:checkbox id="pie" path="pie" onChange="togglePieLines()" /></td>
</tr>
<tr id="pieReason" style="display: none;">
<td><spring:message code="units.pieJustification"/></td>
<td>
<div class="uk-form-row">
<form:select path="pieReason" items="${pieReasonList}" class="uk-form-width-medium" />
</div>
</td>
</tr>
<tr id="pieSince" style="display: none;">
<td><spring:message code="units.pieSince"/></td>
<td>
<div class="uk-form-icon">
<i class="uk-icon-calendar"></i>
<form:input path="pieSince" data-uk-datepicker="{format:'DD.MM.YYYY'}" class="uk-form-width-medium" />
</div>
</td>
</tr>
</tbody>
</table>
<!-- Anwendungsparameter -->
<table class="uk-table uk-table-condensed uk-text-small">
<thead>
<tr>
<th><spring:message code="units.applicationParameters"/></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="uk-width-1-1"><spring:message code="units.legalForm"/></td>
<td class="uk-width-1-1">
<div class="uk-form-row">
<form:select path="legalForm" items="${legalFormList}" class="uk-form-width-medium" />
</div>
</td>
</tr>
<tr>
<td><spring:message code="units.group"/></td>
<td><form:checkbox path="consolidationType" /></td>
</tr>
</tbody>
</table>
<!-- Verantwortlichkeiten -->
<table class="uk-table uk-table-condensed uk-text-small">
<thead>
<tr>
<th><spring:message code="units.responsibilities"/></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td class="uk-width-1-1"><spring:message code="units.responsibleUnit"/></td>
<td class="uk-width-1-1">
<div class="uk-form-row">
<form:select path="responsibleUnit" items="${userList}" class="uk-form-width-medium" />
</div>
</td>
</tr>
<tr>
<td><spring:message code="units.responsibleRotation"/></td>
<td>
<div class="uk-form-row">
<form:select path="responsibleRotation" items="${userList}" class="uk-form-width-medium" />
</div>
</td>
</tr>
<tr>
<td><spring:message code="units.responsibleNonAudit"/></td>
<td>
<div class="uk-form-row">
<form:select path="responsibleNonAudit" items="${userList}" class="uk-form-width-medium" />
</div>
</td>
</tr>
</tbody>
</table>
<div class="input-center">
<button class="uk-button" type="submit"><i class="uk-icon-save"></i> <spring:message code="button.save"/></button>
<button class="uk-button" type="reset"><i class="uk-icon-undo"></i> <spring:message code="button.reset"/></button>
<a class="uk-button" href="<%=request.getContextPath()%>/unitsOverview"><i class="uk-icon-arrow-left"></i> <spring:message code="button.back"/></a>
<br>
</div>
</form:form>
<c:if test="${not empty showParentUnits}">
<form:form commandName="parentUnit" method="post" action="parentUnits" class="uk-form">
<!-- Zuordnung übergeordneter Einheiten -->
<table class="uk-table uk-table-condensed uk-text-small">
<thead>
<tr>
<th colspan="6"><spring:message code="units.parentsAssignment"/></th>
</tr>
</thead>
<tbody>
<tr>
<td class="uk-text-left"> <spring:message code="units.parent"/></td>
<td class="uk-text-center"><spring:message code="units.share"/></td>
<td class="uk-text-center"><spring:message code="units.usb"/></td>
<td class="uk-text-center"><spring:message code="units.fullLiability"/></td>
<td class="uk-text-center"><spring:message code="units.consolidation"/></td>
<td class="uk-text-center"></td>
<tr>
<tr>
<td>
<div class="uk-form-row">
<form:select path="parentUnitId" items="${unitList}" class="uk-form-width-medium" />
</div>
</td>
<td class="uk-text-center"><input type="text" class="uk-form-width-mini"></td>
<td class="uk-text-center"><input type="text" class="uk-form-width-mini"></td>
<td class="uk-text-center"><input type="checkbox"></td>
<td class="uk-text-center"><input type="checkbox"></td>
<td class="uk-text-center"><button class="uk-button" type="submit"><i class="uk-icon-plus"></i></button></td>
</tr>
</tbody>
</table>
</form:form>
</c:if>
</div>
</body>
<script>
function togglePieLines() {
if ($('#pie').prop('checked')) {
$('#pieReason').fadeIn(400);
$('#pieSince').fadeIn(400);
}
else {
$('#pieReason').fadeOut(400);
$('#pieSince').fadeOut(400);
}
}
</script>
</html>
Controller:
package de.amana.marc;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import de.amana.marc.model.ParentUnit;
import de.amana.marc.model.Unit;
import de.amana.marc.service.ParentUnitService;
import de.amana.marc.service.UnitService;
#Controller
public class UnitsController
{
private UnitService unitService;
#Autowired(required=true)
#Qualifier(value="unitService")
public void setUnitService(UnitService us){
this.unitService = us;
}
private ParentUnitService parentUnitService;
#Autowired(required=true)
#Qualifier(value="parentUnitService")
public void setParentUnitService(ParentUnitService pus){
this.parentUnitService = pus;
}
#RequestMapping(value = "/units", method = RequestMethod.GET)
public String unitForm(Model model, HttpServletRequest request, HttpServletResponse response) {
model = this.unitService.fillFormSelectBoxes(model);
// Formobjekte
model.addAttribute("unit", new Unit());
model.addAttribute("parentUnit", new ParentUnit());
return "units";
}
#RequestMapping(value="/units", method =RequestMethod.POST)
public String unitFormSubmit(#Valid #ModelAttribute Unit unit, BindingResult result, Model model) {
model = this.unitService.fillFormSelectBoxes(model);
//Validierung
if (result.hasErrors()) {
return "units";
}
else {
// Speichern in DB
this.unitService.addUnit(unit);
// Zuordnung übergeordneter Gesellschaften einblenden
model.addAttribute("showParentUnits", true);
// Form neu befüllen
model.addAttribute("unit", unit);
model.addAttribute("unitList", this.unitService.listUnits());
ParentUnit newPu = new ParentUnit();
newPu.setUnitId(unit.getUnitId());
model.addAttribute("parentUnit", newPu);
return "units";
}
}
#RequestMapping(value="/parentUnits", method =RequestMethod.POST)
public String parentUnitFormSubmit(#Valid #ModelAttribute ParentUnit parentUnit, BindingResult result, Model model) {
// Formobjekt bearbeiten vor Speichern
ParentUnit newPu = new ParentUnit();
model = this.unitService.fillFormSelectBoxes(model);
return "units";
}
}
Full Stacktrace:
Sometimes the Stacktrace changes to:
This is kinda wierd, because i should be in submit and i have no clue why the first form has the problem
Could you try to use attribute "modelAttribute" on your first form like this and use it in your controller Parameter like the same name:
<form:form commandName="unit" method="post" action="units" class="uk-form" id="unitForm" modelAttribute="unit">
and your second form also the same name in the Controller Parameter:
<form:form commandName="parentUnit" method="post" action="parentUnits" class="uk-form" modelAttribute="parentUnit">
Be sure to add the same name as added attribute in your model to access in your success .jsp

using org.apache.commons.fileupload to upload an image in mysql database but calling the servlet gives a blank white page

I want to upload details of a hoarding in mysql database with an image using .jsp and servlet but when i call my servlet it gives a blank page..
My .jsp
<form action="HoardingProfile" method="post" enctype="multipart/form-data">
<table style="height: 100%; width:100%;">
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Location</h3>
</td>
<td style="width: 50%;">
<input type="text" class="tx bk" name="txtLocation"
placeholder="Location" required="yes">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Size</h3>
</td>
<td class="padd10" style="width: 50%;">
<input class="tx bk" type="text" name="txtSize" placeholder="Size"
required="yes">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Owner Name</h3>
</td>
<td style="width: 50%;">
<input type="text" class="tx bk" placeholder="Owner Name"
required="yes" name="txtName">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Contact No.</h3>
</td>
<td style="width: 50%;">
<input type="text" class="tx bk" placeholder="Number"
required="yes" name="txtNumber">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Address</h3>
</td>
<td style="width: 50%;">
<textarea class="tx bk2" placeholder="Address" required="yes"
name="txtAddress"></textarea>
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 15%;">
<td class="tdleft" style="width: 50%;">
<h3>Picture</h3>
</td>
<td style="width: 50%;">
<input type="file" name="file" id="file">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Google map</h3>
</td>
<td style="width: 50%;">
<textarea class="tx bk2" placeholder="Google Map iframe"
name="txtMap"></textarea>
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 80%;">
<input class="btn" type="submit" name="Add" value="Save"
</td>
<td style="width: 20%;">
<input class="btn" type="reset" value="Reset"
</td>
</tr>
</table>
</form>
and my servlet
PrintWriter out = response.getWriter();
try {
// Apache Commons-Fileupload library classes
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
if (! ServletFileUpload.isMultipartContent(request)) {
System.out.println("Sorry. No file uploaded");
return;
}
// parse request
List<FileItem> items = sfu.parseRequest(request);
out.print(items);
FileItem txtLocation = (FileItem) items.get(0);
String location = txtLocation.getString();
out.println(location);
FileItem txtSize = (FileItem) items.get(1);
String size = txtSize.getString();
out.println(size);
FileItem txtName = (FileItem) items.get(2);
String name = txtName.getString();
out.println(name);
FileItem txtNumber = (FileItem) items.get(3);
String number = txtNumber.getString();
out.println(number);
FileItem txtAddress = (FileItem) items.get(4);
String address = txtAddress.getString();
out.println(address);
// get uploaded file
FileItem file = (FileItem) items.get(5);
// Connect to Oracle
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/opm?zeroDateTimeBehavior=convertToNull","root","");
con.setAutoCommit(false);
PreparedStatement ps = con.prepareStatement("insert into hprofile(location,size,owner,address,phone,deleted,img) values(?,?,?,?,?,?,?)");
ps.setString(1, location);
ps.setString(2, size);
ps.setString(3, name);
ps.setString(4, number);
ps.setString(5, address);
// size must be converted to int otherwise it results in error
ps.setBinaryStream(6, file.getInputStream(), (int) file.getSize());
ps.executeUpdate();
con.commit();
con.close();
out.println("Proto Added Successfully. <p> <a href='listphotos'>List Photos </a>");
}
catch(Exception ex) {
out.println( "Error --> " + ex.getMessage());
}
finally {
out.close();
}
I found out that I made some mistakes while linking the libraries...

Categories