I am trying to handle the form-data and put it in the data base derbi that comes with netbeans.The server i am using is Glassfish. After filling the form when i click the submit data button, according to the action handler the request should follow to a servlet named FormHandler.do but when i try to reach out to the page FormHandler.do this is the error message displayed by the browser :
This webpage is not found
No webpage was found for the web address:
file:///W:/UnderTest/WebApplication_GLASSFISH/src/java/FormHandler/FormHandler.do
Error 6 (net::ERR_FILE_NOT_FOUND): The file or directory could not be found.
But the file is there in the same directory as the html file (that has form). This is the type of url i give in the form tag:
<form method="post" action="FormHandler.do">
<b>Name:</b><input type="text" name="Name" /> <br /> <br />
<b>Email:</b><input type="email" name="Email" /> <br /> <br />
<b>Password:</b><input type="password" name="Password" /> <br /> <br />
<input type="submit" value="Register" />
What could be the reason for this problem ?
(After the request goes to the servlet FormHandler.do it checks (as per logic) if the text fields are empty. If they are empty it forwards the request to a servlet that shows the errors and if correct it inserts that data into the database and shows the success servlet.)
No webpage was found for the web address:
file:///W:/UnderTest/WebApplication_GLASSFISH/src/java/FormHandler/FormHandler.do
You need to access web resources by a HTTP path, not by a local disk file system path. Something like as:
http://localhost:8080/WebApplication_GLASSFISH/FormHandler.do
The /WebApplication_GLASSFISH part is the context path. It's unclear which one you're using, but this information is printed in the server's startup log. Something like as this:
INFO: WebApplication_GLASSFISH was successfully deployed in 3,770 milliseconds.
You need to make sure that the URL in your browser address bar matches this.
Also, HTML files should go in "Web Pages", not in "Source Packages". After you move the Registration.html into "Web Pages", you can open it by
http://localhost:8080/WebApplication_GLASSFISH/Registration.html
This way the form will submit to the proper servlet URL assuming that you've a
<form action="FormHandler.do">
This all is rather trivial. I'd suggest to go through a bit decent Servlet book/tutorial once again. Put your mouse above the servlets tag which you put below the question and click at the info link to get a good starting point.
Related
Hi I wrote the below code in a jsp file to upload a file. But before I upload I want to display the entire path of the file in the current jsp itself
<form method="post" action="SendTheFileName">
<div id="Files_to_be_shared">
<input type="file" id="File" name="FileTag" />
<input type="submit" value="Share" />
</div>
Complete path of the file is <%=request.getParameter("File");%>//Is this correct?
I am not getting the complete path value. I get null instead. Can you please let me know how to get the complete path in the current jsp itself
Jsp's are made on the server and file is uploaded by user, in browser, by the time it will be uploaded - there will be no scriplets on your html page at all, meaning those parameter value will be tried to obtain during jsp creating, where it is obviously null(unless request really contains such value). To run code on the client use javascript, for example here is how to do what you want using javascript.
P.S. consider using EL, scriplets are considered harmful, there are plenty of info about this on the net
I am currently working with JSP, Java servlets.
I am adding custom error messages for a form, I am following the example found on this site http://materializecss.com/forms.html under 'Custom Error or Success Messages'. What I want to do is once the user submits information it gets processed through a java servlet, if the Java servlet find an error with the users input, I want to enable the red error line that appears when an invalid input is entered.
The code I currently have is
<input type="email" name="email" id="email" value="${param.email}" class="validate">
<label for="email" data-error="Invalid Email" data-success="">Email</label>
Each email address has to be unique, so if the email entered is a valid email address then the user would submit the form, and when processing through the java servlet it would find that the email was already used and it will cause the <label> in the jsp page to turn red once the page reloads.
The solution to the question is that on the server side (java servlet) I would pass data into an argument
request.setAttribute("emailError", "error with email");
and on the client side (JSP) I did:
<input type="email" name="email" id="email" value="${param.email}" class="validate" <c:if test="${ not empty emailError}">style="border-bottom: 2.5px solid red; "</c:if> >
<label for="email" data-error="Invalid Email" data-success="">Email</label>
And if you wanted to also display the message from the Java servlet you could add
title="${emailError}"
to the input tag. This would create an additional message box to display the error message.
With this code, if a error is found on the server side, a message would be set and once the JSP page reloads the input line would be red indicating that an error happened.
Using liferay 6.2, I'm currently trying to create a portlet where a image is displayed.
I have already done this but I need to be able to change the image from the preferences uploading a new one. I already have a form to upload a file but I'm not able to upload the file and show it on the portlet.
This is the form in the edit.jsp
<aui:form action="<%=editPreferencesURL%>" method="post">
<aui:input label="image" name="Image" type="file"/>
<aui:button type="submit" />
</aui:form>
This is the renderURL:
<portlet:renderURL var="editPreferencesURL">
<portlet:param name="mvcPath" value="/html/folder/edit.jsp" />
</portlet:renderURL>
The editPreferencesURL that you mention is a renderURL - for posting a form you'll need an actionURL.
A renderURL is typically used to show the raw form (e.g. it's fine to use it to link to the edit mode form) but not for updating data. During render a portlet cannot change state, during action it can.
I'm facing an issue as to redirecting my website to a certain specific URL...
to better explain, I'm adding an auto refresh meta to the top of my jsp that refreshes the web page every 15 minutes, the only problem here is that when the 15 minutes are over, instead of refreshing the same page (thus calling the same servlet to recalculate what needs to be recalculated) it redirects to the home page!(defined in xml as login.jsp)
Now I've tried to debug the code to see which part is redirecting to the home page but it seems that it's no power of my own! it's probably something Tomcat is doing that I'm not aware of. It already happened to me before and the solution was to add an attribute to the session scope session.setAttribute("User",user);
but not this time...
To support my point(It's not a session problem), here's a portion of the code directly extracted from the page source code after redirection
<header>
<h1>WelcomeTV</h1>
</header>
<section>
<form action="Login" method="post">
<ul>
<li><label for="username">Username</label></li>
<li><input type="text" name="user" id="username" placeholder="Your Username" value="wtv_administratifs"></li>
<li><label for="password">Password</label></li>
<li><input type="password" name="password" id="password" placeholder="Your Password"></li>
<li><input type="submit" value="Log in"></li>
</ul>
<p class="reset_pwd">Reset your password</p>
<p class="change_pwd">Change your password</p>
</form>
</section>
You can see that the value is filled, and in my jsp the value is taking ${sessionScope.username} so this proves that the session is still valid
Please help me? if it's not clear please let me know, I'll try to make myself clearer.
Set up your session config in your web xml to -1 if you do not want it to expire
Well, This is embarrassing... It seems the little problem I have has nothing to do with the previous one I resolved with an input into the session scope.
The issue was simply that the URL after logging into my website stays //Context/Login (HTTP POST ><) and with the meta auto refresh, it does not refresh the servlet called after the login, it actually refreshes the same URL displayed above => Login and thus redirects me to the login page...
Issue resolved by adding
<META HTTP-EQUIV="refresh" CONTENT="900;URL=http://10.84.18.53:8080/Welcome_TV/display"> which is the servlet that needs to do all the recalculation.
Issue resolved, thank you for you comments and terribly sorry for your time :)
Using IE 7, JDK 1.6 and Sun Web server 7.
Inside the jsp form, we have:
<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="send" value="Send"/>
i.e. a text box and a "Submit" button (called Send).
and the servlet has:
if (request.getParameter("send") != null && request.getParameter("send").trim().length() > 0) { ... }
Using Fiddler and IE, we can see that the following is sent when we populate the id text box and hit Enter:
id=123456
However, using Fiddler and IE, we can see that the following is sent when we populate the id text box and click the Send button:
userId=123456&send=Send
The end result is that hitting the Enter key effectively does nothing.
On other jsp pages, e.g. we have:
<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="submitId" value="Submit"/>
and the servlet has:
if (request.getParameter("submitId") != null && request.getParameter("submitId").trim().length() > 0) { ... }
Using Fiddler and IE, we can see that the following is sent for both cases:
id=123456&submitId=Submit
So it seems to us that the behaviour is only exhibited on IE for forms where the "Submit" button is not called "Submit"?
Re-running the tests on Firefox 3.6 shows that the behaviour is correct and the same for both cases.
Any suggestions for getting IE to work correctly?
(Note: I have searched SO for a similar problem but the questions relating to this mainly all ASP related!).
This is indeed another IE anomaly in case of forms with only one input field. The only solid workaround for this is to add a second input field(!). You can hide it using CSS. No, type="hidden" ain't going to work.
<input type="text" name="id" maxlength="20" />
<input type="text" style="display: none;" />
<input type="submit" name="send" value="Send"/>
Why are you checking for request.getParameter("submitId") in your JSP when in fact submitId is the name of your submit button?
In my experience I never had to check the value for the submit button. I only used that button to trigger the form submit and would usually only be interested in retrieving the values for the other form parameters.
If you want to differentiate the submit methods by the name of the submit button, you might want to try adding a "hidden" property using input type="hidden".