I'm trying to design a page using jsp-servlet which will help user to upload documents for a case / client. Here is how it should work -
Select client from a list available in option box
Based on selection - basic information about clients will be
displayed
control to upload files will be activated
User can then upload documents one by one
Save Details will save clientID and DocumentNames in MySQL
tables.
I've figured out steps #1 to #5 individually and they are working fine. Problem starts when I bring them on one page. Then I realized because my form has enctype="multipart/form-data", other values populated on form (clientID, name, etc) are not accessible in my controller in order to save Both Client and Document information in MYSQL table.
It would be great help if someone can guide me / point me to an example to follow. Thank you very much for all the help.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.cts.controller;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import com.cts.dao.CaseDocumentDAO;
import com.cts.model.CaseDocument;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CaseDocumentController extends HttpServlet {
private static final long serialVersionUID = 1L;
private static String INSERT_OR_EDIT = "/ctsCaseDocuments.jsp";
//private static String LIST_CASEDETAIL = "/ctsListCaseDetail.jsp";
private CaseDocumentDAO dao;
private final String UPLOAD_DIRECTORY = "d:/uploads";
public CaseDocumentController() {
super();
dao = new CaseDocumentDAO();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String forward = "";
String action = request.getParameter("action");
forward = INSERT_OR_EDIT;
request.setAttribute("casemasters", dao.getAllCaseMaster());
RequestDispatcher view = request.getRequestDispatcher(forward);
view.forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
CaseDocument casedocument = new CaseDocument();
if (request.getParameter("GetDetails") != null) {
String str = request.getParameter("cad_FileName1");
System.out.println(str);
String selected_Comments[] = request.getParameterValues("cad_FileName1");
for (String comment : selected_Comments) {
System.out.println(comment);
request.setAttribute("casedetail", dao.getCaseDetailById(Integer.parseInt(comment)));
request.setAttribute("casemasters", dao.getAllCaseMaster());
request.getRequestDispatcher("/ctsCaseDocuments.jsp").forward(request, response);
}
}
if (ServletFileUpload.isMultipartContent(request)) {
try {
String fname = null;
String fsize = null;
String ftype = null;
List<FileItem> multiparts = new ServletFileUpload(
new DiskFileItemFactory()).parseRequest(request);
for (FileItem item : multiparts) {
if (!item.isFormField()) {
fname = new File(item.getName()).getName();
fsize = new Long(item.getSize()).toString();
ftype = item.getContentType();
item.write(new File(UPLOAD_DIRECTORY + File.separator
+ fname));
}
}
// File uploaded successfully
request.setAttribute("message", "File Uploaded Successfully");
request.setAttribute("name", fname);
request.setAttribute("size", fsize);
request.setAttribute("type", ftype);
} catch (Exception ex) {
request.setAttribute("message", "File Upload Failed due to "
+ ex);
}
} else {
request.setAttribute("message",
"Sorry this Servlet only handles file upload request");
}
request.getRequestDispatcher("/ctsCaseDocuments.jsp").forward(request, response);
}
}
JSP Code -
<%--
Document : ctsCasePayments
Created on : 27 May, 2016, 10:35:35 AM
Author : Admin
--%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%# page import="java.io.*,java.util.*,java.sql.*"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Upload Case Documents</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/sb-admin.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<link rel="stylesheet" href="css/prism.css">
<link rel="stylesheet" href="css/chosen.css">
<style type="text/css" media="all">
/* fix rtl for demo */
.chosen-rtl .chosen-drop { left: -9000px; }
</style>
<script src="/js/jquery.validate.js"></script>
<script>
$.validator.setDefaults({
submitHandler: function () {
alert("submitted!");
}
});
});</script>
<style>
div.dataTables_wrapper {
width: 1100px;
margin: 0 auto;
}
</style>
<style>
#leftContainer {
float:left;
}
#rightContainer {
float:none;
}
</style>
</head>
<body>
<div id="wrapper">
<!-- Navigation -->
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html">SB Admin</a>
</div>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li class="dropdown">
<i class="fa fa-user"></i> <%=session.getAttribute("name")%> <b class="caret"></b>
<ul class="dropdown-menu">
<li>
<i class="fa fa-fw fa-user"></i> Profile
</li>
<li>
<i class="fa fa-fw fa-envelope"></i> Inbox
</li>
<li>
<i class="fa fa-fw fa-gear"></i> Settings
</li>
<li class="divider"></li>
<li>
<i class="fa fa-fw fa-power-off"></i> Log Out
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="active">
<i class="fa fa-fw fa-dashboard"></i> Dashboard
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> Home <i class="fa fa-fw fa-caret-down"></i>
<ul id="demo" class="collapse">
<li>
Dashboard
</li>
<li>
ARCIL Dashboard
</li>
</ul>
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> Operations <i class="fa fa-fw fa-caret-down"></i>
<ul id="demo1" class="collapse">
<li>
Advocates
</li>
<li>
Users
</li>
<li>
Clients
</li>
<li>
Courts
</li>
<li>
Registrar
</li>
<li>
Case Category
</li>
<li>
Case Stage
</li>
<li>
Documents
</li>
</ul>
</li>
<li>
<i class="fa fa-fw fa-arrows-v"></i> Case <i class="fa fa-fw fa-caret-down"></i>
<ul id="demo2" class="collapse">
<li>
Case Diary
</li>
<li>
Case Documents
</li>
<li>
Notice Information
</li>
<li>
Allocate Cases
</li>
<li>
Payments
</li>
</ul>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Maintain Case Expenses
</h1>
<ol class="breadcrumb">
<li>
<i class="fa fa-dashboard"></i> Dashboard
</li>
<li class="active">
<i class="fa fa-edit"></i> Maintain Case Expenses
</li>
</ol>
</div>
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-6">
<%-- <form role="form" method="POST" class="register" action='CaseExpensesController' name="frmAddCaseDetail" onsubmit="return ValidateEndDate(this)">--%>
<form role="form" method="POST" class="register" action='CaseDocumentController' name="frmUploadDocuments" >
<div class="form-group">
<p>
<table>
<tr>
<td>
<select data-placeholder="Select Case..." name ="cad_FileName1" class="chosen-select" style="width:450px;" >
<c:forEach items="${casemasters}" var="casemaster">
<option value="${casemaster.cad_ID}" ${casedetail.cad_ID == casemaster.cad_ID ? 'selected' : ''}>${casemaster.cad_CaseNo} || ${casemaster.cad_FileName}</option>
</c:forEach>
</select>
</td>
<td> <lable> </lable> </td>
<td><button type="submit" name="GetDetails" value="GetDetails" class="btn btn-primary">Get Details</button> </td>
<td> <lable> </lable> </td>
<td><button type="submit" name="AddCase" value="AddCase" class="btn btn-primary">New Case</button> </td>
</tr>
</table>
</p>
<div class="form-group">
<p>
<table>
<tr>
<td><input type="text" readonly="readonly" style="width:200px;" class="form-control" placeholder="Case ID" name="cad_id" value="<c:out value="${casedetail.cad_ID}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:220px;" class="form-control" placeholder="Registration No" name="cad_RegNo" value="<c:out value="${casedetail.cad_RegNo}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:250px;" class="form-control" placeholder="Case Number" name="cad_CaseNo" value="<c:out value="${casedetail.cad_CaseNo}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:250px;" class="form-control" placeholder="File Number" name="cad_FileNo" value="<c:out value="${casedetail.cad_FileNo}" />" /> </td>
</tr>
</table>
</p>
<p>
<table>
<tr>
<td><input type="text" readonly="readonly" style="width:475px;" class="form-control" placeholder="File Name" name="cad_FileName" value="<c:out value="${casedetail.cad_FileName}" />" /> </td>
<td> <lable> </lable> </td>
<td><input type="text" readonly="readonly" style="width:475px;" class="form-control" placeholder="Client Name" name="cad_ClientName" value="<c:out value="${casedetail.cad_ClientName}" />" /> </td>
</tr>
</table>
</p>
<input type="hidden" readonly="readonly" style="width:200px;" class="form-control" placeholder="CaseExpenseID" name="cce_ID" value="<c:out value="${caseexpense.cce_ID}" />" />
<input type="hidden" readonly="readonly" style="width:200px;" class="form-control" placeholder="Case ID" name="pcad_ID" value="<c:out value="${caseexpense.cad_ID}" />" />
<input type="hidden" class="form-control" name="cce_DeleteFlag" value="<c:out value="0"/>" />
<input type="hidden" class="form-control" name="cce_ActiveFlag" value="<c:out value="true" />" />
<input type="hidden" class="form-control" name="cce_CreateDate" value="<fmt:formatDate pattern="dd/MM/yyyy" value="<%= new java.util.Date()%>" />" />
<input type="hidden" class="form-control" name="cce_CreateUser" value="<c:out value="1" />" />
<input type="hidden" class="form-control" name="cce_ModifyDate" value="<fmt:formatDate pattern="dd/MM/yyyy" value="<%= new java.util.Date()%>" />" />
<input type="hidden" class="form-control" name="cce_ModifyUser" value="<c:out value="1" />" />
<p>
<%--<button type="submit" name="SaveDetails" value="SaveDetails" class="btn btn-primary" onClick="return ValidateEndDate();">Submit</button> --%>
<button type="submit" name="SaveDetails" value="SaveDetails" class="btn btn-primary" >Submit</button>
<button type="reset" class="btn btn-default">Reset Button</button>
</p>
</div>
</div>
<script type="text/javascript">
function ValidateEndDate() {
var StartDate = document.getElementById('ccd_PreviousDate').value;
var EndDate = document.getElementById('ccd_CurrentDate').value;
var tmpStartDate = StartDate.split("/");
var tmpEndDate = EndDate.split("/");
var eDate = new Date(tmpEndDate[1] + '/' + tmpEndDate[0] + '/' + tmpEndDate[2]);
var sDate = new Date(tmpStartDate[1] + '/' + tmpStartDate[0] + '/' + tmpStartDate[2]);
if (StartDate != '' && StartDate != '' && sDate.getTime() > eDate.getTime()) {
document.getElementById('NextDateError').innerText = "Please ensure that the Next Date is greater than Previous Date"
return false;
}
else
return true;
}
</script>
<script type="text/javascript">
Toggle();
function Toggle() {
if (document.frmAddCaseDetail.cboxToggle.checked) {
return ValidateEndDate();
}
}
</script>
<script>
function ctsOpenCaseStaePopUp() {
window.open("ctsCaseStage.jsp", null, "height=438, width=600, status=yes, toolbar=no, menubar=no, location=no");
}
</script>
<script>
function ctsOpenCourtPopUp() {
window.open("ctsCourtRegistration.jsp", null, "height=480, width=600, status=yes, toolbar=no, menubar=no, location=no");
}
</script>
</form>
<form method="post" action="CaseDocumentController" enctype="multipart/form-data">
Choose a file : <input type="file" name="file"> <input
type="submit" value="upload">
<div id="result">
<h3>${requestScope["message"]}</h3>
<br>
</div>
File name : ${requestScope["name"]}
<br> File size : ${requestScope["size"]}
<br> File type : ${requestScope["type"]}
</form>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<!-- /#wrapper -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
<script src="js/chosen.jquery.js" type="text/javascript"></script>
<script src="js/prism.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
var config = {
'.chosen-select': {},
'.chosen-select-deselect': {allow_single_deselect: true},
'.chosen-select-no-single': {disable_search_threshold: 10},
'.chosen-select-no-results': {no_results_text: 'Oops, nothing found!'},
'.chosen-select-width': {width: "95%"}
}
for (var selector in config) {
$(selector).chosen(config[selector]);
}
</script>
</body>
Related
I would like to user firstly select the filters which is given in search bar dropdown like AREA or PRICE RANGE etc. I do not know how to put filter and also I want to display those search in on same page. I create this in ASP.NET Core MVC using ADO.NET for database using the SQL queries.
My view:
#model IEnumerable<eHouse.Models.RentModel>
<div class="navbar-left-section">
<form>
<div class="wrap">
<div class="search">
<input type="text" class="searchTerm" style="width: 700px; color:#000000; text-align: left;" placeholder="Search Houses">
<button type="submit" class="searchButton" >
<i class="fa fa-search"></i>
</button>
</div>
</div>
</form>
</div>
Here is how I display the data:
<div class="property_information" >
#foreach (var item in Model)
{
<div class="home-info">
<span id="houseid">
</span>
<a href="#" class="home-images">
<img src="#item.pic1" />
</a>
<div class="home-data">
<div class="home-name">
<p>#item.tittle</p>
</div>
<div class="price">
<p>#item.price</p>
</div>
<div class="features">
<span>
#item.bedroom
</span>
<span>
#item.bathroom
</span>
<span>
2
</span>
</div>
<div class="desc">
#item.descrip
</div>
<div class="contact-save">
<a href="#" class="phone_number" id="favorite" onclick="Fav(this)" data-id="#item.id" >
<i class="fas fa-heart" style=" color: white;"></i>
</a>
<div class="popup" onclick="myFunction()">
<a href="tel:+928754756478" class="phone_number" onclick="call()">
</a>
</div>
<div class="popupmsg" onclick="myFunctionmsg()">
<a href="#" class="phone_number open_message" onclick="msg()">
</a>
</div>
<a href="#" class="phone_number" onclick="del(this)" data-id="#item.id">
<i class="fas fa-trash-alt" style=" color: white;"></i>
</a>
</div>
</div>
</div>
}
</div>
Here I want to just display the results of search.
My controller:
public IActionResult Rent(int PageNumber = 1)
{
var data = rdb.GetDataHouse();
var datas = rdb.GetDataHouse();
ViewBag.Data = datas.ToList().Take(6);
ViewBag.Totalpages = Math.Ceiling(data.Count()/6.0);
data = data.Skip((PageNumber - 1) * 6).Take(6).ToList();
return View(data);
}
I tried as below:
In View
#model SearchBarModel
<form asp-action="SearchBarTest">
<a>Filter:</a>
<input list="options" asp-for="FilterProperty" />
<datalist id="options">
<option value="Price"></option>
<option value="Location"></option>
</datalist>
<br />
<a>Range</a>
<input list="range" asp-for="Range"/>
<datalist id="range">
</datalist>
<br />
<input type="submit" value="Submit" />
</form>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script>
$("#FilterProperty").change(function () {
var val = $("#FilterProperty").val()
$("#range option").remove()
if (val == "Price")
{
$("#range").append('<option value="10~20"></option>');
$("#range").append('<option value="20~30"></option>');
}
if (val == "Location")
{
$("#range").append('<option value="China"></option>');
$("#range").append('<option value="American"></option>');
}
});
</script>
Model:
public class SearchBarModel
{
public string FilterProperty { get; set; }
public string Range { get; set; }
}
Controller:
[HttpPost]
public IActionResult SearchBarTest(string FilterProperty,string Range)
{
return View();
}
Result:
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="<%=request.getContextPath()%>/css/style.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<title>회원가입</title>
<style type="text/css">
div{
background-image: "../img/space.jpeg"
}
</style>
<script type="text/JavaScript" src="https://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$("#ajax_idDuplicate").click(function(){
// userID 변수에 id의 입력된 값을 가져오게 함
var id = $("#id").val();
$.ajax({
type: "POST", // GET or POST 전송방법
url: "../UserIdCheckServlet", // 이쪽으로 보낸다(호출URL)
data: {"id": id}, // userID 이름에 userID 데이터 값을 넣어서 보낸다
success: function(result){ // 만약 성공적으로 수행되었다면 result로 값반환
if(result == 1){ // id가 checkMessage인 것에 아래 텍스트 출력
$('#checkMessage').html('사용할 수 있는 아이디입니다.');
} else {
$('#checkMessage').html('사용할 수 없는 아이디입니다.');
}
// id 가 exampleModal인 모달함수 실행시켜서 모달 실행시키기 위해
$('#checkModal').modal("show");
},
error: function(xhr,status,error){
alert(error);
}
});
});
</script>
</head>
<body>
<div id="join-box">
<div>
<a href="<%=request.getContextPath()%>/MainServlet"><img src="
<%=request.getContextPath()%>/img/joinForm/x_button.jpg" border="0" width="15" height="15"
align="right"></a>
<br>
<h2>회원가입</h2><br/>
<span style="color: red;">${msg }</span>
<form action="<%=request.getContextPath()%>/JoinServlet" method="post">
<input type="text" name="name" class="name" placeholder="이름" /><br>
<input type="text" name="id" id="id" class="id" placeholder="아이디 입력" />
 
<!-- <button class="duplicate_check">중복확인</button> -->
<!-- 부트스트랩 테스트 -->
<!-- Button trigger modal -->
<button type="button" value="중복확인" id="ajax_idDuplicate" class="social-signin" data-bs-toggle="modal"data-bs-target="#checkModal">
중복확인
</button>
<!-- Modal -->
<div class="modal fade" id="checkModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">아이디 중복 확인</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body" id="checkMessage">
<!-- 적을 내용 (알람창) -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">닫기</button>
</div>
</div>
</div>
</div>
<!-- 부트스트랩 테스트 -->
<input type="password" name="pw" placeholder="비밀번호 입력" /><br>
연락처 : <br/><select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="018">018</option>
<option value="019">019</option>
</select>
-<input type="text" class="phone" name="phone2">
-<input type="text" class="phone" name="phone3"><br>
성별 :
남자 <input type="radio" name="gender" value="man">
여자 <input type="radio" name="gender" value="woman"><br>
</div>
<div>
<input type="submit" name="signup_submit" value="회원가입" />
</form>
<br>
<br>
<img src=" <%=request.getContextPath()%>/img/home.png" border="0" width="30" height="30" align="center">
</body>
</html>
I am trying to use AJAX, and I am struggling with a problem which I can't find anymore.
Even though I press the button which has id of ajax_idDuplicate, the function which I decided to activate through the button is not working.
and there is no error in a console window and on my web browser. Could you guys help me for a while?
Dom needs to be loaded before you call your function
<script type="text/javascript">
$(document).ready(function() {
$("#ajax_idDuplicate").click(function(){
I can't get the Quill editor to appear.
I have two ejs files, a layout and an add_new(which includes the layout).
layout.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= title %> </title>
<link rel="stylesheet" href="/css/normalize.css">
<link rel="stylesheet" href="/css/skeleton.css">
<link rel="stylesheet" href="/css/styles.css">
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
</head>
<body>
<header class="interface-header">
<h3 class="interface-title">
<a href="/admin" id="interface-title">
Διαχείρηση
</a>
</h3>
<nav class="interface-nav">
<ul class="interface-navbar-list">
<li class="navbar-item">
<a href="/admin/post/addNew" target="_blank" class="navbar-link button button-primary">
Δημιουργία
</a>
</li>
<li class="navbar-item">
<a href="/" target="_blank" class="navbar-link button">
Ιστοσελίδα
</a>
</li>
<li class="navbar-item">
<a href="/login/logout" class="navbar-link button-danger">
Αποσύνδεση
</a>
</li>
</ul>
</nav>
</header>
</body>
</html>
add_new.ejs
<%- include("interface_layout.ejs") %>
<div class="container">
<form action="/admin/posts" method="POST" enctype="multipart/form-data" class="admin-form">
<label for="title">Τίτλος</label>
<input type="text" name="title" id="title" class="u-full-width">
<label for="content">Περιεχόμενο</label>
<textarea name="content" id="content" rows="20" style="display: none;" class="u-full-width"></textarea>
<div id="toolbar"></div>
<div id="editor"><p>hello world</p></div>
<% const choices = ["Συνεντεύξεις", "Θέατρο-Κριτική", "Εικαστικά", "test-ride"] %>
<label>Ετικέτες</label>
<div class="choices">
<% choices.forEach(choice => { %>
<label for="<%= choice %>" class="choice"><%= choice %></label>
<input type="checkbox" id="<%= choice %>" value="<%= choice %>" name="tags" class="switch">
<% }) %>
</div>
<label for="date">Ημερομηνία αρχικής δημοσίευσης</label>
<input type="date" name="publishingDate" i="date">
<label for="image">Εικόνα</label>
<input type="file" name="image" id="image" accept="iamge/gif, image/png, image/jpeg">
<button class="button-primary button" type="submit">Ανέβασμα</button>
</form>
</div>
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<!-- Initialize Quill editor -->
<script>
var options = {
debug: "info",
modules: {
toolbar: "#toolbar"
},
placeholder: "Compose an epic...",
readOnly: true,
theme: "snow"
}
var container = document.getElementById("editor");
var quill = new Quill(container, options);
</script>
I'm trying to first use quill using the cdn. I import the css for the snow theme in my layout.ejs and in the end of add_new.ejs i import quill and then I initialize it with a script tag. I can't get it to appear.
My console gives me this:
Content Security Policy: The page’s settings blocked the loading of a
resource at https://cdn.quilljs.com/1.3.6/quill.js (“script-src”).
I have also tried to "const Quill = require("quill")" in my routes.js and pass the editor as a variable to my view but I get.
var elem = document.createElement('div');
^
ReferenceError: document is not defined
at Object. (/node_modules/quill/dist/quill.js:7661:12)
I tried the quickstart method (on quill's website) on a plain index.html file and a basic express project with one ejs file and quill worked both times. I suspect there is something wrong with the includes/templates?
I get an error when viewing the browser console, what you need to do is put the highlight.min.js file in front of quill.js. Best to download locally
<link href="/css/quill_editor/quill.snow.css" rel="stylesheet">
<script src="/js/quill_editor/highlight.min.js"></script>
<script src="/js/quill_editor/quill.js"></script>
Below I have Displayed how exactly we can send data from quill/ejs to any backend.
<!-- Include stylesheet -->
<link
href="https://cdn.quilljs.com/1.3.6/quill.snow.css"
rel="stylesheet">
<form action="/add-quill" method="post">
<div id="editor">
</div>
<input name="about" type="hidden">
<input type="submit" onclick="myFunction()">
</form>
<!-- Create the editor container -->
<!-- Include the Quill library -->
<script
src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<!-- Initialize Quill editor -->
<script>
function myFunction() {
<!-- Here the class ql-editor is defined by quill js, we can access the inner html from here -->
var editor = document.getElementsByClassName('ql-editor')[0].innerHTML
var about = document.querySelector('input[name=about]');
about.value = editor
};
//Configuring quill
var quill = new Quill('#editor', {
theme: 'snow'
});
</script>
This question already has answers here:
Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
(9 answers)
Closed 5 years ago.
my code is
AddBookCategory.java
package com.bhim.admin;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bhim.dbConnection.DBConnection;
#WebServlet(name = "category", urlPatterns = "/addCategory")
public class AddBookCategory extends HttpServlet {
#Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws
ServletException, IOException {
// for checking
System.out.println("reached here...");
DBConnection dbConnection=new DBConnection();
try {
dbConnection.open();
String query="insert into `bookcategory`(`c_name`) values(?)";
PreparedStatement preparedStatement=dbConnection.gePreparedStatement(query);
preparedStatement.setString(1, req.getParameter("category"));
int i=preparedStatement.executeUpdate();
if(i>0) {
System.out.println("Insert Successfully");
// req.getRequestDispatcher("admin/addCategory.jsp").forward(req, resp);
resp.sendRedirect("admin/addCategory.jsp");
}
else{
System.out.println("insertion Failed...");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e)
e.printStackTrace();
}
}
}
addCategory.jsp
<jsp:include page="adminHeader.jsp" />
<center>
<div class="content">
<form action="${pageContext.request.contextPath}/addCategory" method="get">
<table class="full" border="0">
<tr>
<td><h2>Category Name</h2></td>
</tr>
<tr>
<td><input type="text" name="category" /></td>
</tr>
<tr>
<td><input type="submit" value="Add Category" /></td>
</tr>
</table>
</form>
</div>
</center>
<jsp:include page="../footer.jsp" />
adminheader.jsp
<!DOCTYPE html>
<html>
<head>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<title>Bus Booking System</title>
</head>
<body>
<div id='wrapper'>
<div class="banner">
<h1>Online Library Management System</h1>
<% // Using session...
HttpSession session1 = request.getSession();
String user = (String) session1.getAttribute("user");
%>
<span class="session"> Welcome:<%=user%>
</span>
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Book Category</li>
<li>Books</li>
<li> User Mgmt</li>
<li>Search Book </li>
<li>Check allocated Book</li>
<li> Notification</li>
<li>Logout
</li>
</ul>
</div>
I am trying to forward page from servlet to jsp using RequestDispatcher CSS is not work but i also try sendRedirect css is working.Give me suggestion why css is not working when using requestDispatcher.
The problem I found was in the way you include your css file. If you debug it using Chrome you should see a 404 error loading the style.css file. Try this:
addCategory.jsp
<!DOCTYPE html>
<html>
<head>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<title>Bus Booking System</title>
</head>
<body>
<jsp:include page="adminHeader.jsp" />
<center>
<div class="content">
<form action="${pageContext.request.contextPath}/addCategory" method="get">
<table class="full" border="0">
<tr>
<td><h2>Category Name</h2></td>
</tr>
<tr>
<td><input type="text" name="category" /></td>
</tr>
<tr>
<td><input type="submit" value="Add Category" /></td>
</tr>
</table>
</form>
</div>
</center>
<jsp:include page="../footer.jsp" />
adminHeader.jsp
<div id='wrapper'>
<div class="banner">
<h1>Online Library Management System</h1>
<% // Using session...
HttpSession session1 = request.getSession();
String user = (String) session1.getAttribute("user");
%>
<span class="session"> Welcome:<%=user%>
</span>
</div>
<div class="menu">
<ul>
<li>Home</li>
<li>Book Category</li>
<li>Books</li>
<li> User Mgmt</li>
<li>Search Book </li>
<li>Check allocated Book</li>
<li> Notification</li>
<li>Logout
</li>
</ul>
</div>
I am using the icenium weather example from telerik platorm icenium.com to load a data file json for an test app I am doing
my json is as follows
[
{
"screen_id": "course_outline",
"screen_title": "NICMA Child Minding App - Course Outline",
"screen_display_type": "/json_schema/P14_navigation.schema.json",
"updated": "1371030938",
"author": [
{
"author_name": "Andrew Moran",
"author_url": "http://people.learningpool.com/user/id"
}
],
"comments": "authoring tool metadata, not used in app",
"authoring_tool": {
"version": "x.x",
"href": ""
},
"copyright": "2013 - Learning Pool",
"screen_content": {
"screen_title": "Child Minding Navigation",
"start_text": "Text at the start of the screen",
"navigation_items": [
{
"screen_id": "food_hygiene_legislation_doc",
"screen_display_type": "/json_schema/P03_content_screen.schema.json",
"display_text": "Home"
}
],
"end_text": ""
}
]
I just made a copy of the weather funciton and named it course-outline.js
and added it into my scripts
(function (global) {
var WeatherViewModel,
app = global.app = global.app || {};
WeatherViewModel = kendo.data.ObservableObject.extend({
weatherDataSource: null,
init: function () {
var that = this,
dataSource;
kendo.data.ObservableObject.fn.init.apply(that, []);
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "data/course_outline.json",
dataType: "json"
}
}
});
that.set("weatherDataSource", dataSource);
}
});
app.weatherService = {
viewModel: new WeatherViewModel()
};
})(window);
But for some reason when i click the weather button now it hangs even though ive told the template to find screen_title any ideas
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<link href="kendo/styles/kendo.mobile.all.min.css" rel="stylesheet" />
<link href="styles/main.css" rel="stylesheet" />
<script src="cordova.js"></script>
<script src="kendo/js/jquery.min.js"></script>
<script src="kendo/js/kendo.mobile.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
<script src="scripts/course-outline.js"></script>
<script src="scripts/login.js"></script>
<script src="scripts/location.js"></script>
<script src="scripts/app.js"></script>
</head>
<body>
<!--Home-->
<div id="tabstrip-home"
data-role="view"
data-title="Home">
<div class="view-content">
<h1>Welcome!</h1>
<a id="skin-change" data-role="button" data-click="app.changeSkin">Flat</a>
<p>
Icenium™ enables you to build cross-platform device applications regardless of your
development platform by combining the convenience of a local development toolset with the
power and flexibility of the cloud.
</p>
<div class="img"></div>
</div>
</div>
<!--Login-->
<div id="tabstrip-login"
data-role="view"
data-title="Login"
data-model="app.loginService.viewModel">
<div class="view-content">
<div class="logo"></div>
<h3 data-bind="invisible: isLoggedIn">Enter your credentials:</h3>
<h1 class="welcome" data-bind="visible: isLoggedIn">Welcome, <span data-bind="text: username"></span>!
</h1>
<div class="buttonArea">
<input type="submit" id="logout" data-role="button" data-bind="click: onLogout, visible: isLoggedIn" class="login-button" value="Logout" />
</div>
<form data-bind="events: { keyup: checkEnter }">
<ul data-role="listview" data-style="inset" data-bind="invisible: isLoggedIn">
<li>
<label>
Username
<input type="text" data-bind="value: username" />
</label>
</li>
<li>
<label>
Password
<input type="password" data-bind="value: password" />
</label>
</li>
</ul>
<div class="buttonArea">
<input type="submit" id="login" data-role="button" data-bind="click: onLogin, invisible: isLoggedIn" class="login-button" value="Login" />
</div>
</form>
</div>
</div>
<!--Location-->
<div id="tabstrip-location"
data-role="view"
data-title="Location"
data-init="app.locationService.initLocation"
data-show="app.locationService.show"
data-hide="app.locationService.hide"
data-model="app.locationService.viewModel"
data-stretch="true">
<div id="no-map" data-bind="invisible: isGoogleMapsInitialized">
Location requires internet connection to display the map.
</div>
<div id="map-search-wrap" data-bind="visible: isGoogleMapsInitialized">
<button id="map-navigate-home" data-bind="click: onNavigateHome"></button>
<form onsubmit="return false;">
<input id="map-address" type="search" data-bind="value: address" placeholder="Address" />
<input id="map-search" type="submit" value="" data-bind="click: onSearchAddress" />
</form>
</div>
<div id="map-canvas" data-bind="visible: isGoogleMapsInitialized"></div>
</div>
<!--Weather-->
<div id="tabstrip-weather"
data-role="view"
data-title="Weather"
data-model="app.weatherService.viewModel">
<div class="weather">
<p class="weather-title">Course Title</p>
<div class="separator">
<div class="dark"></div>
<div class="light"></div>
</div>
<ul class="forecast-list"
data-role="listview"
data-bind="source: weatherDataSource"
data-template="weather-forecast-template">
</ul>
</div>
</div>
<!--Weather forecast template-->
<script type="text/x-kendo-tmpl" id="weather-forecast-template">
<div>
<div class="position-left">
<span class="weather-info date">${screen_title}</span>
</div>
<div class="position-right">
<span class="weather-info temperature high">${screen_title}<sup>°</sup></span>
<span class="weather-info temperature low">${screen_title}<sup>°</sup></span>
</div>
</div>
</script>
<!--Layout-->
<div data-role="layout" data-id="tabstrip-layout">
<!--Header-->
<div data-role="header">
<div data-role="navbar">
<span data-role="view-title"></span>
</div>
</div>
<!--Footer-->
<div data-role="footer">
<div data-role="tabstrip">
Home
Login
Location
Weather
</div>
</div>
</div>
</body>
</html>