I've been working with velocity recently, but I made a big mess, what should I do?

Multi tool use
Multi tool use












0














I got this program, that I made: http://www.2shared.com/file/73q6K9Yy/testv.html
The Login.java is the servlet, that should use the login.vm template, and modify it. It doesn't do anything, and I don't understand why.
In the function:



public Template handleRequest(HttpServletRequest request,HttpServletResponse response, Context ctx )


If I put:



 error= (String) request.getAttribute("error");
ctx.put("error", error);


It doesn't do anything.
IF I put:



 error= request.getAttribute("error").toString();
ctx.put("error", error);


I get a Java null pointer exception.
BUT if I put:



 ctx.put("error","this is a string");


It changes the variable of the template login.vm into that string.
Why doesn't it get the Attribute from the request, what I'm a doing wrong.



PS: If I press the Register button, it should redirect me to the "/reg.jsp" page. I made this only to see if it works, and it doesn't. Made the same program in MVC, with jsp's but I need to make it with velocity, for my internship.










share|improve this question
























  • 10x Andrew Aylett for making my question more viewable. :D
    – rosu alin
    Apr 23 '12 at 10:24
















0














I got this program, that I made: http://www.2shared.com/file/73q6K9Yy/testv.html
The Login.java is the servlet, that should use the login.vm template, and modify it. It doesn't do anything, and I don't understand why.
In the function:



public Template handleRequest(HttpServletRequest request,HttpServletResponse response, Context ctx )


If I put:



 error= (String) request.getAttribute("error");
ctx.put("error", error);


It doesn't do anything.
IF I put:



 error= request.getAttribute("error").toString();
ctx.put("error", error);


I get a Java null pointer exception.
BUT if I put:



 ctx.put("error","this is a string");


It changes the variable of the template login.vm into that string.
Why doesn't it get the Attribute from the request, what I'm a doing wrong.



PS: If I press the Register button, it should redirect me to the "/reg.jsp" page. I made this only to see if it works, and it doesn't. Made the same program in MVC, with jsp's but I need to make it with velocity, for my internship.










share|improve this question
























  • 10x Andrew Aylett for making my question more viewable. :D
    – rosu alin
    Apr 23 '12 at 10:24














0












0








0







I got this program, that I made: http://www.2shared.com/file/73q6K9Yy/testv.html
The Login.java is the servlet, that should use the login.vm template, and modify it. It doesn't do anything, and I don't understand why.
In the function:



public Template handleRequest(HttpServletRequest request,HttpServletResponse response, Context ctx )


If I put:



 error= (String) request.getAttribute("error");
ctx.put("error", error);


It doesn't do anything.
IF I put:



 error= request.getAttribute("error").toString();
ctx.put("error", error);


I get a Java null pointer exception.
BUT if I put:



 ctx.put("error","this is a string");


It changes the variable of the template login.vm into that string.
Why doesn't it get the Attribute from the request, what I'm a doing wrong.



PS: If I press the Register button, it should redirect me to the "/reg.jsp" page. I made this only to see if it works, and it doesn't. Made the same program in MVC, with jsp's but I need to make it with velocity, for my internship.










share|improve this question















I got this program, that I made: http://www.2shared.com/file/73q6K9Yy/testv.html
The Login.java is the servlet, that should use the login.vm template, and modify it. It doesn't do anything, and I don't understand why.
In the function:



public Template handleRequest(HttpServletRequest request,HttpServletResponse response, Context ctx )


If I put:



 error= (String) request.getAttribute("error");
ctx.put("error", error);


It doesn't do anything.
IF I put:



 error= request.getAttribute("error").toString();
ctx.put("error", error);


I get a Java null pointer exception.
BUT if I put:



 ctx.put("error","this is a string");


It changes the variable of the template login.vm into that string.
Why doesn't it get the Attribute from the request, what I'm a doing wrong.



PS: If I press the Register button, it should redirect me to the "/reg.jsp" page. I made this only to see if it works, and it doesn't. Made the same program in MVC, with jsp's but I need to make it with velocity, for my internship.







servlets request velocity






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 3:07









Cœur

17.4k9103145




17.4k9103145










asked Apr 23 '12 at 9:57









rosu alin

2,51683898




2,51683898












  • 10x Andrew Aylett for making my question more viewable. :D
    – rosu alin
    Apr 23 '12 at 10:24


















  • 10x Andrew Aylett for making my question more viewable. :D
    – rosu alin
    Apr 23 '12 at 10:24
















10x Andrew Aylett for making my question more viewable. :D
– rosu alin
Apr 23 '12 at 10:24




10x Andrew Aylett for making my question more viewable. :D
– rosu alin
Apr 23 '12 at 10:24












1 Answer
1






active

oldest

votes


















1














My best guess is that there is no attribute under the "error" key in your request. It has nothing to do with Velocity itself. If you check the line number the null exception occurs at, it should be the first line of your code excerpt.



Note that in a web context, you should use the VelocityViewServlet, from the velocity-tools subproject, rather than the deprecated VelocityServlet that will disappear in next versions.






share|improve this answer





















  • I changed it to VelocityViewServlet, and the Properties class to ExtendedProperties ( had an error over there, after changing to extends VelocityViewServlet) and now, when i run the program i get an error like this one: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet velo.Login threw exception What does it mean?
    – rosu alin
    Apr 23 '12 at 11:20












  • I changed it to error= request.getAttribute("error").toString(); to see why do i have a java null pointer exception, and the error, is at this line, it all works fine, till it gets to it. I tried putting a request.getAttribute("error").toString() in other parts of the code, not in the Template function and no errors. PS: In the template (login.vm) how do i declare <%@page import="a.userBean"%>
    – rosu alin
    Apr 23 '12 at 11:39












  • Internal errors generally have a root cause which gives more informations. You should check your servlet container log file if the displayed internal error is not explicit enough. If you don't solve related problems by yourself, please try to identify and post here only the most relevant lines. Your P.S. has nothing to do with your original question. I guess you will have to put your userBean somewhere (why not as a session attribute?) from your Java code. Remember that you can reach J2EE attributes from within your templates with $request, $session and $application.
    – Claude Brisson
    Apr 23 '12 at 12:45










  • 10x, will do so as soon as i get back to the office
    – rosu alin
    Apr 23 '12 at 14:12










  • done, and thanks a lot
    – rosu alin
    Apr 26 '12 at 12:52











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10278355%2five-been-working-with-velocity-recently-but-i-made-a-big-mess-what-should-i-d%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














My best guess is that there is no attribute under the "error" key in your request. It has nothing to do with Velocity itself. If you check the line number the null exception occurs at, it should be the first line of your code excerpt.



Note that in a web context, you should use the VelocityViewServlet, from the velocity-tools subproject, rather than the deprecated VelocityServlet that will disappear in next versions.






share|improve this answer





















  • I changed it to VelocityViewServlet, and the Properties class to ExtendedProperties ( had an error over there, after changing to extends VelocityViewServlet) and now, when i run the program i get an error like this one: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet velo.Login threw exception What does it mean?
    – rosu alin
    Apr 23 '12 at 11:20












  • I changed it to error= request.getAttribute("error").toString(); to see why do i have a java null pointer exception, and the error, is at this line, it all works fine, till it gets to it. I tried putting a request.getAttribute("error").toString() in other parts of the code, not in the Template function and no errors. PS: In the template (login.vm) how do i declare <%@page import="a.userBean"%>
    – rosu alin
    Apr 23 '12 at 11:39












  • Internal errors generally have a root cause which gives more informations. You should check your servlet container log file if the displayed internal error is not explicit enough. If you don't solve related problems by yourself, please try to identify and post here only the most relevant lines. Your P.S. has nothing to do with your original question. I guess you will have to put your userBean somewhere (why not as a session attribute?) from your Java code. Remember that you can reach J2EE attributes from within your templates with $request, $session and $application.
    – Claude Brisson
    Apr 23 '12 at 12:45










  • 10x, will do so as soon as i get back to the office
    – rosu alin
    Apr 23 '12 at 14:12










  • done, and thanks a lot
    – rosu alin
    Apr 26 '12 at 12:52
















1














My best guess is that there is no attribute under the "error" key in your request. It has nothing to do with Velocity itself. If you check the line number the null exception occurs at, it should be the first line of your code excerpt.



Note that in a web context, you should use the VelocityViewServlet, from the velocity-tools subproject, rather than the deprecated VelocityServlet that will disappear in next versions.






share|improve this answer





















  • I changed it to VelocityViewServlet, and the Properties class to ExtendedProperties ( had an error over there, after changing to extends VelocityViewServlet) and now, when i run the program i get an error like this one: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet velo.Login threw exception What does it mean?
    – rosu alin
    Apr 23 '12 at 11:20












  • I changed it to error= request.getAttribute("error").toString(); to see why do i have a java null pointer exception, and the error, is at this line, it all works fine, till it gets to it. I tried putting a request.getAttribute("error").toString() in other parts of the code, not in the Template function and no errors. PS: In the template (login.vm) how do i declare <%@page import="a.userBean"%>
    – rosu alin
    Apr 23 '12 at 11:39












  • Internal errors generally have a root cause which gives more informations. You should check your servlet container log file if the displayed internal error is not explicit enough. If you don't solve related problems by yourself, please try to identify and post here only the most relevant lines. Your P.S. has nothing to do with your original question. I guess you will have to put your userBean somewhere (why not as a session attribute?) from your Java code. Remember that you can reach J2EE attributes from within your templates with $request, $session and $application.
    – Claude Brisson
    Apr 23 '12 at 12:45










  • 10x, will do so as soon as i get back to the office
    – rosu alin
    Apr 23 '12 at 14:12










  • done, and thanks a lot
    – rosu alin
    Apr 26 '12 at 12:52














1












1








1






My best guess is that there is no attribute under the "error" key in your request. It has nothing to do with Velocity itself. If you check the line number the null exception occurs at, it should be the first line of your code excerpt.



Note that in a web context, you should use the VelocityViewServlet, from the velocity-tools subproject, rather than the deprecated VelocityServlet that will disappear in next versions.






share|improve this answer












My best guess is that there is no attribute under the "error" key in your request. It has nothing to do with Velocity itself. If you check the line number the null exception occurs at, it should be the first line of your code excerpt.



Note that in a web context, you should use the VelocityViewServlet, from the velocity-tools subproject, rather than the deprecated VelocityServlet that will disappear in next versions.







share|improve this answer












share|improve this answer



share|improve this answer










answered Apr 23 '12 at 10:58









Claude Brisson

2,1931417




2,1931417












  • I changed it to VelocityViewServlet, and the Properties class to ExtendedProperties ( had an error over there, after changing to extends VelocityViewServlet) and now, when i run the program i get an error like this one: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet velo.Login threw exception What does it mean?
    – rosu alin
    Apr 23 '12 at 11:20












  • I changed it to error= request.getAttribute("error").toString(); to see why do i have a java null pointer exception, and the error, is at this line, it all works fine, till it gets to it. I tried putting a request.getAttribute("error").toString() in other parts of the code, not in the Template function and no errors. PS: In the template (login.vm) how do i declare <%@page import="a.userBean"%>
    – rosu alin
    Apr 23 '12 at 11:39












  • Internal errors generally have a root cause which gives more informations. You should check your servlet container log file if the displayed internal error is not explicit enough. If you don't solve related problems by yourself, please try to identify and post here only the most relevant lines. Your P.S. has nothing to do with your original question. I guess you will have to put your userBean somewhere (why not as a session attribute?) from your Java code. Remember that you can reach J2EE attributes from within your templates with $request, $session and $application.
    – Claude Brisson
    Apr 23 '12 at 12:45










  • 10x, will do so as soon as i get back to the office
    – rosu alin
    Apr 23 '12 at 14:12










  • done, and thanks a lot
    – rosu alin
    Apr 26 '12 at 12:52


















  • I changed it to VelocityViewServlet, and the Properties class to ExtendedProperties ( had an error over there, after changing to extends VelocityViewServlet) and now, when i run the program i get an error like this one: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet velo.Login threw exception What does it mean?
    – rosu alin
    Apr 23 '12 at 11:20












  • I changed it to error= request.getAttribute("error").toString(); to see why do i have a java null pointer exception, and the error, is at this line, it all works fine, till it gets to it. I tried putting a request.getAttribute("error").toString() in other parts of the code, not in the Template function and no errors. PS: In the template (login.vm) how do i declare <%@page import="a.userBean"%>
    – rosu alin
    Apr 23 '12 at 11:39












  • Internal errors generally have a root cause which gives more informations. You should check your servlet container log file if the displayed internal error is not explicit enough. If you don't solve related problems by yourself, please try to identify and post here only the most relevant lines. Your P.S. has nothing to do with your original question. I guess you will have to put your userBean somewhere (why not as a session attribute?) from your Java code. Remember that you can reach J2EE attributes from within your templates with $request, $session and $application.
    – Claude Brisson
    Apr 23 '12 at 12:45










  • 10x, will do so as soon as i get back to the office
    – rosu alin
    Apr 23 '12 at 14:12










  • done, and thanks a lot
    – rosu alin
    Apr 26 '12 at 12:52
















I changed it to VelocityViewServlet, and the Properties class to ExtendedProperties ( had an error over there, after changing to extends VelocityViewServlet) and now, when i run the program i get an error like this one: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet velo.Login threw exception What does it mean?
– rosu alin
Apr 23 '12 at 11:20






I changed it to VelocityViewServlet, and the Properties class to ExtendedProperties ( had an error over there, after changing to extends VelocityViewServlet) and now, when i run the program i get an error like this one: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: Servlet.init() for servlet velo.Login threw exception What does it mean?
– rosu alin
Apr 23 '12 at 11:20














I changed it to error= request.getAttribute("error").toString(); to see why do i have a java null pointer exception, and the error, is at this line, it all works fine, till it gets to it. I tried putting a request.getAttribute("error").toString() in other parts of the code, not in the Template function and no errors. PS: In the template (login.vm) how do i declare <%@page import="a.userBean"%>
– rosu alin
Apr 23 '12 at 11:39






I changed it to error= request.getAttribute("error").toString(); to see why do i have a java null pointer exception, and the error, is at this line, it all works fine, till it gets to it. I tried putting a request.getAttribute("error").toString() in other parts of the code, not in the Template function and no errors. PS: In the template (login.vm) how do i declare <%@page import="a.userBean"%>
– rosu alin
Apr 23 '12 at 11:39














Internal errors generally have a root cause which gives more informations. You should check your servlet container log file if the displayed internal error is not explicit enough. If you don't solve related problems by yourself, please try to identify and post here only the most relevant lines. Your P.S. has nothing to do with your original question. I guess you will have to put your userBean somewhere (why not as a session attribute?) from your Java code. Remember that you can reach J2EE attributes from within your templates with $request, $session and $application.
– Claude Brisson
Apr 23 '12 at 12:45




Internal errors generally have a root cause which gives more informations. You should check your servlet container log file if the displayed internal error is not explicit enough. If you don't solve related problems by yourself, please try to identify and post here only the most relevant lines. Your P.S. has nothing to do with your original question. I guess you will have to put your userBean somewhere (why not as a session attribute?) from your Java code. Remember that you can reach J2EE attributes from within your templates with $request, $session and $application.
– Claude Brisson
Apr 23 '12 at 12:45












10x, will do so as soon as i get back to the office
– rosu alin
Apr 23 '12 at 14:12




10x, will do so as soon as i get back to the office
– rosu alin
Apr 23 '12 at 14:12












done, and thanks a lot
– rosu alin
Apr 26 '12 at 12:52




done, and thanks a lot
– rosu alin
Apr 26 '12 at 12:52


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f10278355%2five-been-working-with-velocity-recently-but-i-made-a-big-mess-what-should-i-d%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







2 Np61bgFSrzj9aPByFKorey6XoJr5DHnyRvTR DmWrinU3bk,8KOff0zWrdwrd8S7,Rx35,Lv,2bxVZzUS0QB5fJM04A
BdbFEW35BKRz H6tD1IV XtCUbxWHC7sgzKcSWFLF5 BPWowrR9XhCXdX,H4f

Popular posts from this blog

Monofisismo

compose and upload a new article using a custom form

“attempting to read past stream EOM” using Sybase.AdoNet4.AseClient