Eclipse 404 error page not found - spring-mvc

I am trying spring MVC program and this is my directory structure when I run this program it works properly and when I hit the enter key and direct it to the next page i.e the action page.
it shows this page
HTTP Status 404 - /MVC_HelloWorld/hello.ap
type Status report
message /MVC_HelloWorld/hello.ap
description The requested resource is not available.
In my form action page I have written
this my inde.jsp page
<h1> Hello World</h1>
<form action="./hello.ap">
NAME: <input type="text" name="name">
<input type="Submit" value="Say Hello">
</form>
Is the problem with the path or directory structure is wrong?

The directory structure as I can see is correct. But the action you are setting in the form should be only the text like "hello.ap" it should not include / or ./ try with hello.ap and name the requestMaping in your controller to hello.ap.

Related

call Telegram.api in browser (Windows): sendPhoto

I am using Telegram to send pictures from a IP-cam.
This can be done on raspberry-PI like this:
curl -s -X POST "https://api.telegram.org/bot123456789:yourcode/sendPhoto" -F chat_id=123456789 -F photo="#/volume1/Data/temp/picture.jpeg"
Explanation: the picture is in the folder "/volume1/Data/temp" the name is "picture.jpeg"
I want to do the same on Windows and I constantly get message "{"ok":false,"error_code":400,"description":"Bad Request: Wrong persistent file_id specified: contains wrong characters or has wrong length"}"
This is exactly (exact for the bot and yourcode and chatid) what I transmit in the address of Google Chrome:
https://api.telegram.org/bot123456789:yourcode/sendPhoto?chat_id=123456789&photo="#C:/temp/picture.jpeg"
I can assure you the is no problem with autorisation (filling in file:///C:/temp/picture.jpeg in the browser shows me the picture).
And I have tried al kinds of variantions (with and without #, with and without ", etc. etc.). I cannot get it working.
And it works with sending text:
...../sendMessage?chat_id=123456789&text=”hello”
result is that I get the message "hello" and this in the browser: {"ok":true,"result":{"message_id" ......
I am sure I am close but do not know how to define exactly the "picture".
So the questions is: what is the exact way to transmit a picture with Telegram through a Windows browser using api.telegram.org? Please provide an example that is working.
Thanks in advance for help!
When you transmit that url in chrome (or any other browser) you are actually using "GET" method than can be used for send image with its "file_id".
But when you want to upload a file from your pc, you should use "POST" method to send it.
On of easiest ways is using a HTML form.
For an example:
<form action="https://api.telegram.org/bot2222222:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/sendPhoto" method="post" enctype="multipart/form-data">
<input type="text" name="chat_id" value="11111111" />
<input type="file" name="photo" />
<input type="submit" value="send" />
</form>
Edit:
Also if you want to do it from command line you can use windows version of cUrl. You can download it from this link:
Windows cUrl
or use Invoke-RestMethod in windows powershell.
example command:
Invoke-RestMethod -Uri $uri -Method Post -InFile $filePath -ContentType "multipart/form-data"

PHP - Cannot read uploaded temporary file

I'm holding a mail service on my VPS who has a web interface by Roundcube
But I recently found that my Roundcube cannot upload avatars of contacts correctly (which was my first try of uploading avatars). So I had a look of the code and found that it failed when reading properties of the uploaded temporary picture file.
To figure out whether it was caused by Roundcube or not, I wrote a simple script.
<html>
<body>
<form method="post" action="/upload.php" enctype="multipart/form-data">
<input type="file" name="test">
<button type="submit">Upload</button>
</form>
</body>
</html>
<?php
var_dump($_FILES);
var_dump(file_exists($_FILES['test']['tmp_name']));
// read the properties by GD, as what Roundcube does
$props = getimagesize($_FILES['test']['tmp_name']);
var_dump($props);
And the output was:
array(1) {
["test"]=> array(5) {
["name"]=> string(23) "kanakurayui_2_small.png"
["type"]=> string(9) "image/png"
["tmp_name"]=> string(14) "/tmp/php7OxqPq"
["error"]=> int(0)
["size"]=> int(49294)
}
}
bool(false)
bool(false)
It looks like that the file was immediately deleted after uploaded, however I could call move_uploaded_file() to move the temporary file to another directory (so the mail attachment is functioning properly).
I'm running Ubuntu 14.04 with Nginx 1.6.2 and PHP-FPM 5.6.7 from repositories of LaunchPad. And the script works correctly on my local machine whose environment is exactly the same.
I think the problem is caused by some certain configuration of Nginx or PHP, but after checking the configuration files, I could only find configurations about the size and time limit.
I'm really confused now. Please help, thanks.
UPDATE
Apache 2.4 + PHP works properly on the same VPS.
I finally solved the problem myself. Thanks #insanebits for reminding.
I had a look at the Nginx log and found the following message:
PHP message: PHP Warning: getimagesize(): open_basedir restriction in effect. File(/tmp/php1PACw4) is not within the allowed path(s): (/var/www) in /var/www/test/upload.php on line 5
So I moved the temporary directory to /tmp/php and add /tmp/php to the open_basedir setting in php.ini
The reason why it worked on my local machine was that my local PHP configuration was a copy for development and the open_basedir was commented out.

Un block delete method in nginx

When I tried to use delete method on nginx I get 403 access denied
<HTML>
<HEAD>
<TITLE>Access Denied</TITLE>
</HEAD>
<BODY BGCOLOR="white" FGCOLOR="black">
<H1>Access Denied</H1>
<HR>
<FONT FACE="Helvetica,Arial">
<B>
Description: You are not allowed to access the document you requested.
</B>
</FONT>
<HR>
</BODY>
I have searched configuration for any default block for delete method, but I can't find. I want to enable delete method in nginx, how can I do this?
UPDATE:
I don't log entry for delete alone but I can see for remaining all(get,post,patch,copy,head,unlink,put,options,link).

R download file redirect

Hi I am following a online class and trying to download the rda dataset provided by the prof.
I tried to run exactly the same command as provided in the class:
download.file("https://dl.dropbox.com/u/7710864/courseraPublic/samsungData.rda", destfile="./samsungData.rda", method="curl")
load('./samsungData.rda')
When I go to the download folder, open the rda file in vi, this is what I see:
<html>
<head><title>Found</title></head>
<body>
<h1>Found</h1>
<p>The resource was found at https://dl.dropboxusercontent.com/u/7710864/courseraPublic/samsungData.rda;
you should be redirected automatically.
<!-- --></p>
<hr noshade>
<div align="right">WSGI Server</div>
</body>
</html>
Clearly there is a redirect here and the download file command did not follow it smartly. When I open up that URL in the browser, it will be successfully redirected.
I took a look at the help manual of download.file there is no such thing as following redirect.
Can anyone show me how to follow the redirect?
Try specifying an extra argument, which will pass command-line arguments to curl:
download.file("https://dl.dropbox.com/u/7710864/courseraPublic/samsungData.rda",
destfile="./samsungData.rda",
method="curl",
extra='-L')

How to show customized 404 error page - Symfony2

I have this in my controller:
if(some stuff) {
throw $this->createNotFoundException('message');
}
When I test it in dev env, I get the Symfony's page telling Exception detected with my text, but I can't test it in prod env :( I run this php app/console cache:clear --env=prod --no-debug and then replace only in the URL app_dev.php with app.php but the toolbar and Symfony's error page stay.
I created this file - app/Resources/TwigBundle/views/Exception/error.html.twig. So will it be rendered in prod?
This is in it:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>An Error Occurred: {{ status_text }}</title>
</head>
<body>
<h1>Oops! An Error Occurred</h1>
<h2>The server returned a "{{ status_code }} {{ status_text }}".</h2>
</body>
</html>
where should I give values for status_code and status _text? Or they are taken from the exception?
So in general what I want to do is when a condition in my contoller`s action is true, mine customized error page to be shown in prod env. Did I make it already, and if not, how to make it and how to see the result in prod env?
I also tried and i noticed that custom error pages placed in app/Resources/TwigBundle/views/Exception/error.html.twig worked only in prod environment.
Better late than never I guess..
You probably know about overriding of templates.
You can override any template you want.
So if you want to override the dev error page, just for debugging, then you should override the template:
exception_full.html.twig
You can do so by creating such a file in this folder:
app/Resources/TwigBundle/views/Exception
Now you will see your customized 404 in dev mode.
you can access your detected text with following way:
{{ exception.message }}
Read the doc http://symfony.com/doc/2.0/cookbook/controller/error_pages.html
and Customizing the 404 Page and other Error Pages
http://symfony.com/doc/2.0/cookbook/controller/error_pages.html#customizing-the-404-page-and-other-error-pages
It appears Symfony has a new way of allowing you to see the error page templates in your dev environment. Taken from their docs:
While you're in the development environment, Symfony shows the big exception page instead of your shiny new customized error page. So, how can you see what it looks like and debug it?
Fortunately, the default ExceptionController allows you to preview your error pages during development.
To use this feature, you need to have a definition in your routing_dev.yml file like so:
# app/config/routing_dev.yml
_errors:
resource: "#TwigBundle/Resources/config/routing/errors.xml"
prefix: /_error
Read more: Symfony Error Pages Manual

Resources